Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

gcd is too slow

Posted by frkstyc at 2006-03-28 02:57:47 on Problem 2773
In 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator