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 |
WA了无数次……#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator