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 |
Re:呜呜,styc说帖代码要被鄙视的,可我实在没办法了。。。比赛时WA了N次,现在有N次了,救命啊!!!In Reply To:呜呜,styc说帖代码要被鄙视的,可我实在没办法了。。。比赛时WA了N次,现在有N次了,救命啊!!! Posted by:qywyh at 2006-03-27 00:47:45 #include <iostream> using namespace std; const MAX = 1001; int main() { bool test[MAX]; int prime[MAX]; int i, j; int primeTotal; int inNum[1000001]; int relaPrime[1000000]; int m, k, kk; bool flag; int tmpK, sumPrime; int p; for (i=0; i < MAX; i++) { test[i] = true; } primeTotal = 0; for (i=2; i < MAX; i++) { if (test[i]) { prime[primeTotal++] = i; for (j=2; j <= MAX/i; j++) { test[i*j] = false; } } } while (cin >> m >> k) { if (m == 1) { cout << k << endl; continue; } for (i=1; i <= m; i++) { inNum[i] = 0; } for (i=0; i < primeTotal; i++) { if (m % prime[i] == 0) { for (j=1; j <= m/prime[i]; j++) { inNum[prime[i]*j] = -1; } } } sumPrime = 0; for (i=1; i<m; i++) { if (inNum[i] != -1) { relaPrime[sumPrime++] = i; } } if (k <= sumPrime) { cout << relaPrime[k-1] << endl; } else { if (k%sumPrime == 0) { cout << (m*(k/sumPrime-1)+relaPrime[sumPrime-1]) << endl; } else { cout << (m*(k/sumPrime)+relaPrime[k%sumPrime-1]) << endl; } } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator