22 組合數學 Ploya定理(手鐲定理);

Problem B Buildings

Problem B Buildings As a traveling salesman in a globalized world, Alan has always moved a lot. He almost never lived in the same town for more than a few years until his heart yearned for a different place. However, this newest town is his favorite yet - it is just so colorful. Alan has recently moved to Colorville, a smallish city in between some really nice mountains. Here, Alan has finally decided to settle down and build himself a home - a nice big house to call his own. In Colorville, many people have their own houses - each painted with a distinct pattern of colors such that no two houses look the same. Every wall consists of exactly n × n squares, each painted with a given color (windows and doors are also seen as unique “colors”). The walls of the houses are arranged in the shape of a regular m-gon, with a roof on top. According to the deep traditions of Colorville, the roofs should show the unity among Colorvillians, so all roofs in Colorville have the same color. Figure B.1: Example house design for n = 3, m = 6. Of course, Alan wants to follow this custom to make sure he fits right in. However, there are so many possible designs to choose from. Can you tell Alan how many possible house designs there are? (Two house designs are obviously the same if they can be translated into each other just by rotation.) Input The input consists of: • one line with three integers n, m, and c, where – n (1 ≤ n ≤ 500) is the side length of every wall, i.e. every wall consists of n × n squares; – m (3 ≤ m ≤ 500) is the number of corners of the regular polygon; – c (1 ≤ c ≤ 500) the number of different colors. GCPC 2017 Problem B: Buildings 3 Output Output s where s is the number of possible different house designs. Since s can be very large, output s mod (109 + 7).

Sample Input 1

Sample Output 1

1 3 1

1

Sample Input 2

Sample Output 2

2 5 2

209728

手鐲定理:就是一個手鐲是由n個珠子構成的,現在呢我們有k中顏色,沒個珠子可以染成這k種顏色中的任意一種,讓我們來求算一下我們可以染出多少種本質上並不相同的手環來;

這裏有一個定理公式: L  =  1 /  |G| (k^c[0]+ k^c[1] + k^ c[2] + k^c[3]+k^c[4]+.......k^c[|G-1|]);

1)這裏的L就是我們要求的方案數:其中|G|是我們要染色的手鐲的長度(珠子的個數),k是我們有多少種顏色,

c[i]=gcd(n,i);

2)就是逆元如果我們想除以一個數然後在取模的話會出問題,但是我們知道b乘以b的逆元(b^-1)等於1

那麼我麼求a/b等於(a*b^-1)/(b*b^-1)所以我們就可以看到a/b就等於a乘以b^-1,在

涉及到逆元問題費馬小定理b^(p-1)modp=1modp==>b*b^(p-2)modp=1modp;

如果一個數字取模的話就是他的逆元就是這個數的取模數減掉2的次方;

公式中的每一個變量的含義都有了我們可以直接來求了這到題目的意思是有一個柱體有m個面每個面上有n×n個格子,我們

現在有c種顏色最多可以染成本質不同的柱體,抽象一下的話就是我們有一個長度是m的手鐲,現在有(m^(n^2))種

顏色我們最多可以染成多少種本質並不相同的手鐲來呢

|G| = m, K =m^(n^2), c[i]可以由m求出顯然。。。。。。

#include <bits/stdc++.h>
using namespace std;
const int Max = 1e5+10;
const int mod = 1e9+7;
#define rep(i,s,n) for(ll i=s;i<=n;i++)
#define per(i,n,s) for(ll i=n;i>=s;i--)
typedef long long ll;
ll qpow(ll base , ll k){//求逆元
   ll res=1ll;
   while(k){
    if(k&1){
        res=res*base%mod;
        res=(res%mod+mod)%mod;
    }
    base=base*base%mod;
    base=(base%mod+mod)%mod;
    k/=2;
   }
   return (res%mod+mod)%mod;
}
ll gcd(ll a, ll b){ return b==0? a : gcd(b,a%b);}
ll sum,ans,cc[Max],c[Max],n,m,k,base;
int main(){
    scanf("%lld %lld %lld",&n,&m,&k);
    base=1;
    rep(i,1,n*n)  {
      base=base*k%mod;
      base=(base%mod+mod)%mod;
    }
    k=base;
    cc[0]=1;
    rep(i,1,m){
      cc[i]=cc[i-1]*k;
      cc[i]=(cc[i]%mod+mod)%mod;
    }
    rep(i,0,m-1){
       c[i]=gcd(i,m);
    }
    sum=0;
    rep(i,0,m-1){
       sum+=cc[c[i]];
       sum=(sum%mod+mod)%mod;
    }
    ans=qpow(m,mod-2);
    sum=sum*ans%mod;
    sum=(sum%mod+mod)%mod;
    printf("%lld\n",sum);
    return 0;
}
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章