HDU3441:Rotation(Polya)
来源:互联网 发布:剑灵辅助软件 编辑:程序博客网 时间:2024/06/14 19:27
传送门
题意:有一个
题解:
Polya找出每个
#include<iostream>#include<cstdio>#include<algorithm>#include<vector>using namespace std;struct IO{ streambuf *ib,*ob; inline void init() { ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); ib=cin.rdbuf();ob=cout.rdbuf(); } inline int read() { static char ch; static int i,f; i=0,f=1;ch=ib->sbumpc(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=ib->sbumpc();} while(isdigit(ch)){i=((i+(i<<2))<<1)+ch-'0';ch=ib->sbumpc();} return (f==1)?i:-i; } inline void W(int x) { static int buf[50]; if(!x){ob->sputc('0');return;} if(x<0){ob->sputc('-');x=-x;} while(x)buf[++buf[0]]=x%10,x/=10; while(buf[0]){ob->sputc(buf[buf[0]--]+'0');} return; } inline void W(string x) { int len=x.length(); for(int i=0;i<len;i++)ob->sputc(x[i]); }}io;typedef pair<int,int> pii;int A,C,ans;const int Mod=1e9+7;vector<int>factory;vector<pii>fac2;vector<pii>fac3;inline void fac(int a){ for(int d=2;d*d<=a;d++) { if(a%d)continue; while(!(a%d))factory.push_back(d),a/=d; } if(a!=1)factory.push_back(a);}inline void getfac(int a){ factory.clear(); fac(a+1),fac(a-1); sort(factory.begin(),factory.end()); fac2.clear();fac3.clear(); fac2.push_back(make_pair(factory[0],1)); for(int e=1;e<factory.size();e++) (factory[e]!=factory[e-1])?(fac2.push_back(make_pair(factory[e],1))):((void)fac2[fac2.size()-1].second++);}inline int power(int a,long long b){ int res=1; for(;b;b>>=1,a=1ll*a*a%Mod)(b&1)?(res=1ll*res*a%Mod):0; return res;}inline void dfs2(int pos,long long sze,long long phi,int &res,long long all,int k){ if(pos==fac3.size()) { (res+=1ll*phi%Mod*power(k,1ll*all/sze)%Mod)%=Mod; return; } dfs2(pos+1,sze,phi,res,all,k); for(int i=1;i<=fac3[pos].second;i++) { sze*=fac3[pos].first; (i==1)?(phi*=(fac3[pos].first-1)):(phi*=(fac3[pos].first)); dfs2(pos+1,sze,phi%Mod,res,all,k); }}inline int calcsum(long long n,int k){ int res=0; dfs2(0,1,1,res,n,k); return res;}inline int calckind(int a){ int res=0; (res+=1ll*power(C,1ll*a*a))%=Mod; (res+=2ll*power(C,1ll*a*a/4+(a&1))%Mod)%=Mod; (res+=1ll*power(C,1ll*a*a/2+(a&1)))%=Mod; return 1ll*res*power(4,Mod-2)%Mod;}inline void calc(int b){ long long res=(1ll*A*A-1)/b/b; (ans+=1ll*calcsum(res,calckind(b))*C%Mod*power(res%Mod,Mod-2)%Mod)%=Mod;}inline void dfs(int b,int pos){ if(pos==fac2.size()){calc(b);} else { fac3.push_back(make_pair(fac2[pos].first,fac2[pos].second)); dfs(b,pos+1); for(int i=2;i<=fac2[pos].second;i+=2) { b=b*fac2[pos].first; fac3[fac3.size()-1].second-=2; dfs(b,pos+1); } fac3.erase(--fac3.end()); }}int main(){ io.init();int T=io.read(); for(int tt=1;tt<=T;tt++) { A=io.read(),C=io.read();ans=0; io.W("Case ");io.W(tt);io.W(": "); if(A==1){io.W(C);io.ob->sputc('\n');continue;} getfac(A); dfs(1,0); io.W(ans);io.ob->sputc('\n'); }}
阅读全文
0 0
- HDU3441:Rotation(Polya)
- 【hdu3441】Rotation,Polya套Polya
- HDU 3441 Rotation (两次Polya!!!!)
- HDU 3441 Rotation(Polya计数)
- UIView 旋转(rotation)
- 旋转(Rotation)手势
- 旋转(Rotation)手势
- polya
- polya
- Polya
- Polya
- POJ 2154 Color Polya(Polya定理+欧拉函数)
- polya 定理小结 (转)
- poj2286The Rotation Game(IDA*)
- iOS旋转手势 (Rotation )
- SGU 282 Isomorphism(polya)
- HDU 3923 Invoker(polya)
- POJ 2154 Color(polya)
- 51nod 1080 两个数的平方和
- tensorflow学习——爬虫(headers爬取图片)
- Android开源项目及库整理总结 字数10731 阅读2704 评论2 喜欢85 自己总结的Android开源项目及库。 github排名https://github.com/trending,
- Android AIDL接口方法详解
- Kylin Cube构建过程优化
- HDU3441:Rotation(Polya)
- quartz数据库说明
- Android第三方推送到达率调研
- Unity IniFile 保存游戏数据到本地文件
- 【转】Web网站测试流程和方法
- 1111
- JS的同步与异步
- 日期类函数(计算日期)
- easyui-datagrid 合并单元格