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迅速水过

Posted by aa2985759 at 2010-11-30 17:52:31 on Problem 3090
#include<iostream>
using namespace std;
int gcd(int i,int j)
{
	int k;
	while(i%j)
	{
		k=j;
		j=i%j;
		i=k;
	}
	return j;
}
int main()
{
	int n,k=1,i,a[1001];
	a[1]=3,a[2]=5;
	for(n=3;n<=1000;n++)
	{
		for(i=1;i<n;i++)
				if(gcd(n,i)==1)k++;
		a[n]=k*2+3;
	}
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>k;
		cout<<i+1<<" "<<k<<" "<<a[k]<<endl;
	}
}
	

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