求助!!帮忙看看有什么问题

P1304 哥德巴赫猜想

```cpp for (int j = 2; j <= sqrt(N); j++) ``` **把 j <= sqrt(N) 改成 j <= N 就AC了.**
by zheng_zx @ 2023-10-18 13:42:27


除了@cheng_zx说的,你的代码我感觉怪怪的说不出来的那种。 ``` #include <bits/stdc++.h> using namespace std; int n; bool isp(int x){ if(x==2) return true; if(x<2 || x%2==0) return false; for(int i=3;i*i<=x;i+=2) if(x%i==0) return false; return true; } void work(int n){ for(int i=2;i<n;i++) if(isp(i) && isp(n-i)){ printf("%d=%d+%d\n",n,i,n-i); return; } } int main(){ cin>>n; for(int i=4;i<=n;i+=2)work(i); return 0; } ``` 仅供参考,禁止抄题解!!!
by panghanchen2012 @ 2023-10-31 11:05:35


|