poj2409 & poj2154 & hdu4633(Polya定理)

Let it Bead
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6242 Accepted: 4187

Description

"Let it Bead" company is located upstairs at 700 Cannery Row in Monterey, CA. As you can deduce from the company name, their business is beads. Their PR department found out that customers are interested in buying colored bracelets. However, over 90 percent of the target audience insists that the bracelets be unique. (Just imagine what happened if two women showed up at the same party wearing identical bracelets!) It's a good thing that bracelets can have different lengths and need not be made of beads of one color. Help the boss estimating maximum profit by calculating how many different bracelets can be produced. 

A bracelet is a ring-like sequence of s beads each of which can have one of c distinct colors. The ring is closed, i.e. has no beginning or end, and has no direction. Assume an unlimited supply of beads of each color. For different values of s and c, calculate the number of different bracelets that can be made.

Input

Every line of the input file defines a test case and contains two integers: the number of available colors c followed by the length of the bracelets s. Input is terminated by c=s=0. Otherwise, both are positive, and, due to technical difficulties in the bracelet-fabrication-machine, cs<=32, i.e. their product does not exceed 32.

Output

For each test case output on a single line the number of unique bracelets. The figure below shows the 8 different bracelets that can be made with 2 colors and 5 beads.

Sample Input

1 1
2 1
2 2
5 1
2 5
2 6
6 2
0 0

Sample Output

1
2
3
5
8
13
21

Polya定理基础应用

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b)
{
	return b>0?gcd(b,a%b):a;  
}
LL Polya(LL n,LL m)
{
	LL sum=0;
	LL tmp;
	for(LL i=1;i<=n;i++)
	{
		tmp=gcd(n,i);
		sum+=(LL)pow(1.0*m,1.0*tmp);
	}
	if(n&1)
	{
		sum+=(LL)(n*pow(1.0*m,(n+1)/2.0));
	}
	else
	{
		sum+=(LL)((n/2)*pow(1.0*m,(n+2)/2.0));
		sum+=(LL)((n/2)*pow(1.0*m,n/2.0));
	}
	sum=sum/(2*n);
	return sum;
}
int main()
{
	LL c,s;
	while(~scanf("%lld%lld",&c,&s)&&(c||s))
	{
		LL ans=Polya(s,c);
		printf("%lld\n",ans);
	}
}





Color
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 11097 Accepted: 3595

Description

Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). Your job is to calculate how many different kinds of the necklace can be produced. You should know that the necklace might not use up all the N colors, and the repetitions that are produced by rotation around the center of the circular necklace are all neglected. 

You only need to output the answer module a given number P. 

Input

The first line of the input is an integer X (X <= 3500) representing the number of test cases. The following X lines each contains two numbers N and P (1 <= N <= 1000000000, 1 <= P <= 30000), representing a test case.

Output

For each test case, output one line containing the answer.

Sample Input

5
1 30000
2 30000
3 30000
4 30000
5 30000

Sample Output

1
3
11
70
629


Polya定理加上Euler函数优化,Euler函数也需要时埃式筛法优化过的。

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
int MOD;
const int maxn = 100000+10;  
int prime[maxn];     //第i个素数  
bool is_prime[maxn];    //is_prime[i]为true表示i是素数  
//返回n以内的素数的个数  
int sieve(int n)  
{  
    int p = 0;  
    memset(is_prime,true,sizeof(is_prime)); 
    is_prime[0] = is_prime[1] = false;  
    for (int i = 2; i <= n; i++){  
        if (is_prime[i]){  
            prime[p++] = i;  
            for (int j = 2 * i; j <= n; j += i)  
                is_prime[j] = false;  
        }  
    }  
    return p;  
}  
int Euler(int n)
{
    int ret=n;
    for(int i=0;prime[i]*prime[i]<=n;i++)
    {
    	if(n%prime[i]==0)
    	{
	        ret=ret/prime[i]*(prime[i]-1);//先进行除法防止溢出(ret=ret*(1-1/p(i)))
	        while(n%prime[i]==0)
	          n/=prime[i];
    	}
    }
    if(n>1)
          ret=ret/n*(n-1);
    return ret%MOD;
}

int quick_pow(int a,int b)
{
	int ans=1;
	a=a%MOD;
	while(b)
	{
		if(b&1)ans=(ans*a)%MOD;
		b>>=1;
		a=(a*a)%MOD;
	}
	return ans;
}

int Polya(int n,int m)
{
	int sum=0;
	for(int l=1;l*l<=n;l++)
	{
		if(l*l==n)
		{
			sum=(sum+(Euler(n/l)*quick_pow(m,l-1))%MOD)%MOD;
		}
		else if(n%l==0)
		{
			sum=(sum+(Euler(n/l)*quick_pow(m,l-1))%MOD)%MOD;
			sum=(sum+(Euler(l)*quick_pow(m,n/l-1))%MOD)%MOD;
		}
	}
	return sum%MOD;
}
int main()
{
	sieve(maxn);
	int t;
	int n,p;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d%d",&n,&p);
		MOD=p;
		int ans=Polya(n,n);
		printf("%d\n",ans);
	}
}


Who's Aunt Zhang

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 589    Accepted Submission(s): 482


Problem Description
Aunt Zhang, well known as 张阿姨, is a fan of Rubik’s cube. One day she buys a new one and would like to color it as a gift to send to Teacher Liu, well known as 刘老师. As Aunt Zhang is so ingenuity, she can color all the cube’s points, edges and faces with K different color. Now Aunt Zhang wants to know how many different cubes she can get. Two cubes are considered as the same if and only if one can change to another ONLY by rotating the WHOLE cube. Note that every face of Rubik’s cube is consists of nine small faces. Aunt Zhang can color arbitrary color as she like which means that she doesn’t need to color the nine small faces with same color in a big face. You can assume that Aunt Zhang has 74 different elements to color. (8 points + 12 edges + 9*6=54 small faces)

 

Input
The first line of the date is an integer T, which is the number of the text cases.
Then T cases follow, each case contains one integer K, which is the number of colors. T<=100, K<=100.
 

Output
For each case, you should output the number of different cubes.
Give your answer modulo 10007.
 

Sample Input
  
  
3 1 2 3
 

Sample Output
  
  
Case 1: 1 Case 2: 1330 Case 3: 9505

见代码:

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define MOD 10007
int quick_pow(int a,int b)
{
	int ans=1;
	a=a%MOD;
	while(b)
	{
		if(b&1)ans=(ans*a)%MOD;
		b>>=1;
		a=(a*a)%MOD;
	}
	return ans;
}
int Polya(int m)   //n为置换物体个数,m为颜色数
{
	int sum=0;
	//不动 
	//8+12+54=74
	sum=(sum+quick_pow(m,74.0))%MOD;
	
	//绕点转
	//18+(2+2)+(2+2)=26
	//x2x4
	sum=(sum+(quick_pow(m,26.0)*8)%MOD)%MOD;
	
	//绕面转
	//90° & 270°  (9x1+3x2)+(1x2+1)+2=20
	//180°     (9x2+5x2)+(2x2+2)+4=38 
	//x3
	sum=(sum+(quick_pow(m,20.0)*6)%MOD)%MOD;
	sum=(sum+(quick_pow(m,38.0)*3)%MOD)%MOD;
	
	//绕线中心转
	// (18+9)+(2+1+4)+4=38
	//x6
	sum=(sum+(quick_pow(m,38)*6)%MOD)%MOD;
	sum=(sum*417)%MOD;
	return sum;
}
int main()
{
//	cout<<quick_pow(24,10005)<<endl;
	int t;
	int k;
	scanf("%d",&t);
	for(int tt=1;tt<=t;tt++)
	{
		scanf("%d",&k);
		printf("Case %d: %d\n",tt,Polya(k));
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值