Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我的100题!!!!!!加油,高大上的数论#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; typedef long long ll; ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } ll geteuler(ll n) { ll ans=n; int m=(int)sqrt(n+0.5); for(int i=2; i<=m; i++) if(n%i==0) { ans=ans/i*(i-1); while(n%i==0) n/=i; } if(n>1) ans=ans/n*(n-1); return ans; } ll multi(ll a,ll b,ll n) { ll ans=0; while(b>0) { if(b&1) ans=(ans+a)%n; b>>=1; a=(a*2)%n; } return ans; } ll quick_mod(ll a,ll b,ll n) { ll ret=1; while(b>0) { if(b&1) ret=multi(ret,a,n); b>>=1; a=multi(a,a,n); } return ret; } ll a[200010]; int main() { ll p,q; int cas=0; while(scanf("%lld/%lld",&p,&q)!=EOF) { //printf("%lld %lld\n",p,q); ll d=gcd(p,q); p/=d; q/=d; ll x=0,y=0; while(!(q&1)) { x++; q>>=1; } x++; ll phi=geteuler(q); int k=0; int m=(int)sqrt(phi+0.5); for(int i=1; i<=m; i++) if(phi%i==0) { a[k++]=i; a[k++]=phi/i; } sort(a,a+k); for(int i=0; i<k; i++) if(quick_mod(2,a[i],q)==1) { y=a[i]; break; } printf("Case #%d: %lld,%lld\n",++cas,x,y); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator