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 |
gcd is too slowIn Reply To:Why TLE? Posted by:songuno1 at 2006-03-28 02:17:37 > #include <stdio.h> > > int N, K; > int d[1000000], Cnt; > > int gcd ( int a, int b ){ > int c; > > for (;;){ > if (a%b==0) return b; > c=a, a=b, b=c%b; > } > } > > int main (){ > int i; > > while ( scanf ( "%d%d", &N, &K )!=EOF ){ > K--; > for (i=1, Cnt=0; i<=N; i++) if (gcd(N,i)==1) d[Cnt++]=i; > printf ( "%d\n", d[K%Cnt]+N*(K/Cnt) ); > } > > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator