|
|
вернуться в форумWA9 please help #include <iostream> using namespace std; bool prime(long long n); int main() { long long a,odd, i, j, nice,b; cin >> a >> b; nice=0; if (a%2==1) {odd=a;} else {odd=a+1;} for (i=b; i>a; i--) { if (prime(i)) { nice=i; break; } } if ((a==1 or nice==0) and b!=a) { cout << odd;} else if (b==a) {cout << a;} else if (nice) {cout << nice << endl;} return 0; } bool prime(long long n) { bool w; w=n==2; if (!w and n%2) { w=1; for (int i=3; i*i<=n; i+=2) { if (n%i==0) { w=0 ; break; } } } if (w) { return 1; } else return 0; } Re: WA9 please help Case "no prime is found" is suspicious. You think answer is the minimal odd number in the interval. Could you prove it? Why not maximal odd number in the interval? Why you don't want to do try brute force? |
|
|