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;
}
 

猜你喜欢

转载自blog.csdn.net/qq_39792342/article/details/82011045
今日推荐