oh my gosh
一直time error的原因是因为定义longlong的n 结果输入%d
就一直time error ctmd。
置换群首先考虑旋转。
然后再考虑翻转 翻转分为奇偶数来考虑总数。
最后除以置换的个数。
/*
qq:1239198605
ctgu_yyf
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
/*
//快速幂
ll powx(ll a,ll b)
{
ll res=1;
if(a==1)
return a;
while(b>0)
{
if(b&1)
res=res*a;
a=a*a;
b=b>>1;
}
return res;
}
*/
ll powx(ll x,ll k) {
if( k == 1 ) return x ;
ll s = pow(x,k/2) ;
s = s*s ;
if( k%2 ) s *= x ;
return s ;
}
int main()
{
// ios::sync_with_stdio(false);
ll n;
while(scanf("%lld",&n) && n != -1)
{
if(n==0)
{
printf("0\n");
continue;}
ll ans=0;
//旋转置换
for(int i=1;i<=n;i++)
ans=ans+powx(3,gcd(n,i));
//翻转置换
//如果n为奇数
if(n%2)
ans=ans+powx(3,n/2+1)*n;
else
{
ans=ans+powx(3,n/2)*(n/2);
ans=ans+powx(3,n/2+1)*(n/2);
}
//cout<<(ans/(n*2))<<endl;
printf("%lld\n",(ans/(n*2)));
}
return 0;
}