用n种颜色给正方体着色共用多少种不同的着色方案



http://exam.upc.edu.cn/problem.php?id=4200


题目大意:

用n种颜色给正方体着色共用多少种不同的着色方案


分析:

根据Polya定理可求得(并不会推只知道公式学会了再来解释)

 res=(n^6 + 3*n^4 + 12*n^3 + 8*n^2)/24 



AC代码:

#include 
#include   
#include   
#include   
#include   
#include   
#include  
#include 
#include    
#include   
#include 
#include   
#include   
#include 
#define mset(a,i) memset(a,i,sizeof(a))
#define SS(s)     scanf("%s",s)
#define S1(n)     scanf("%d",&n)
#define S2(n,m)   scanf("%d%d",&n,&m)
#define P(n)      printf("%d\n",n)
#define FIN       freopen("input.txt","r",stdin)
#define FOUT      freopen("output.txt","w",stdout)
#define gcd(a,b)  __gcd(a,b)
using namespace std;
typedef long long ll;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const int MAX=1e6+5;
const double PI=acos(-1);
int dir[5][2]={0,1,0,-1,1,0,-1,0};
ll qpow(ll n,ll m){n%=mod;ll ans=1;while(m){if(m%2) 
		ans=(ans*n)%mod;m/=2;n=(n*n)%mod;}return ans;}
ll inv(ll b){return b==1?1:(mod-mod/b)*inv(mod%b)%mod;}
ll inv2(ll b){return qpow(b,mod-2);}
int main(){
	int n;
	ll ans1;
	while (scanf ("%d",&n)!=EOF){
		ans1=0;
		ans1=((((qpow(n,6)%mod+3*qpow(n,4)%mod)%mod+12*qpow(n,3)%mod)%mod+8*qpow(n,2)%mod)%mod*inv(24))%mod;
		printf ("%lld\n",ans1);
	}
	return 0;
} 






你可能感兴趣的:(算法,数论专题)