poj 2262
来源:互联网 发布:淘宝windows 编辑:程序博客网 时间:2024/06/02 00:32
很基础的一道数学题,不过感觉跑的太慢啊,422ms
#include <iostream>#include <cmath>using namespace std;const int maxn=1000001;int vis[maxn],p[maxn];int t;void prime(){t=0;int i,j;int n=(int)sqrt(maxn-1);for(i=2;i<=n;i++){if(!vis[i]){p[t++]=i;for(j=i*i;j<=maxn-1;j+=i)vis[j]=1;}}}int main(){int n;prime();while(cin>>n&&n!=0){int a,b;int i,j=0;bool flag1=true,flag2=true;for(i=p[j];i<=(n/2);i=p[++j]){if(!vis[n-i]){flag1=flag2=false;cout<<n<<" = "<<i<<" + "<<n-i<<endl;break;}}if(flag1){j=t-1;for(i=p[j];;i=p[--j]){if(!vis[n-i]){cout<<n<<" = "<<i<<" + "<<n-i<<endl;flag2=false;break;}}}if(flag2)cout<<"Goldbach's conjecture is wrong." <<endl;}return 0;}
- poj 2262
- POJ-2262
- poj 2262
- POJ 2262
- poj 2262
- poj 2262
- poj-2262
- POJ 2262
- POJ 2262
- POJ 2262
- poj 2262
- POJ 2262
- poj 2262 解题报告
- poj 2262 打表
- poj 2262 素数
- POJ 2262
- POJ 2262 解题报告
- POJ 2262 筛素法
- LBP算子介绍
- 线性时间排序之计数排序(JAVA)
- 在Struts2中使用ValueStack、ActionContext、ServletContext、request、session等
- 堆排序
- Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut
- poj 2262
- C#实现截取当前屏幕的方法
- Android反编译查看源文件
- 【转】如何让AlertDialog 在点击确定或者取消时不消失
- 动态规划__合唱队形问题
- I2C串行总线协议的VHDL实现
- adobe你狗日的在玩我?
- apache shiro权限认证类
- C#实现图片压缩