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

WA了无数次……

Posted by speedcell4 at 2011-07-22 11:36:14 on Problem 2773
#include<iostream>
#define SIZE 1000001
using namespace std;
int n,m;
int a[SIZE]={0};
int gcd(int a,int b)
{
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
int findEle(int n,int m)
{
    int j=0;
    for(int i=1;n-i>0;i++)
    {
        if(gcd(n,i)==1) a[j++]=i;
    }
    return ((m-1)/j)*n+a[(m-1)%j];
}
int main()
{
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        if(n==1) printf("%d\n",m);
        else printf("%d\n",findEle(n,m));
    }
    return 0;
}

切忌,输入的第一个数是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