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时栈溢出,推荐使用int Gcd(int a, int b){ return a == 0 ? b : Gcd(b % a, a); }

Posted by xfxyjwf at 2006-05-03 04:07:37 on Problem 2369
In Reply To:请高手们帮我看一下我的代码,为什么runtime error哦??? Posted by:b412860771 at 2006-05-03 01:56:21
> #include<stdio.h>
> long f(long m,long n)
> {
> 	if(m==n)return m;
> 	else if(m>n)return f(m-n,n);
> 	else return f(m,n-m);
> 
> }
> main()
> {
> 	long b[1006],temp=1,x,y,te,s=1;
> 	int n,i,t,a[1006],c[1006],j=1;
> 	scanf("%d",&n);
> 	for(i=0;i<1004;i++)
> 	   c[i]=0;
> 	for(i=1;i<=n;i++)
> 		scanf("%d",&a[i]);		
> 	for(i=1;i<=n;i++)
> 	{
> 		if(c[i]==0)
> 		{
> 			t=a[i];c[i]=1;
> 		    while(i!=t)
> 			{c[t]=1;t=a[t];s=s+1;}
> 			b[j]=s;j++;s=1;
> 		}
> 	}
> 	for(i=2;i<j;i++)
> 	{
> 		x=b[i-1];y=b[i];te=x*y;
> 		temp=f(x,y);
> 		if(temp>0)
> 		  b[i]=te/temp;
> 	}
> 	printf("%ld",b[i-1]);
> }

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