|
|
вернуться в форумWA#6 Help somebody!! Why my code has WA6..or GIVE SOME TESTS, please)) #include<iostream> #include<vector> #include<cmath> using namespace std; vector<int>easy_numbers(0); int next_number(int numb_of_numb) { int step=easy_numbers.size()-1; int curr_number=easy_numbers[step]; while(step+1<numb_of_numb) { while(1) { curr_number++; int sq_root=sqrt(static_cast<double>(curr_number))+1; int buf_step; buf_step=0; while(easy_numbers[buf_step]<sq_root) if (curr_number%easy_numbers[buf_step++]!=0) continue; else goto g1; break; g1: } easy_numbers.push_back(curr_number); step++; } return curr_number; } int main() { int K; int L=-1; cin >> K; if (K==4) {cout << 3; exit(0);} easy_numbers.push_back(3); int buf=0; while((easy_numbers[buf]*easy_numbers[buf])<=K) next_number(++buf); for (int i=0;i<easy_numbers.size();i++) { if (K%easy_numbers[i]==0) {L=easy_numbers[i]-1; break;}
} if (L==-1 && K%2==0) {L=K/2-1; cout << L; exit(0);} if (L==-1) {L=K-1; cout << L; exit(0);} cout << L; return 0; } |
|
|