题目1440:Goldbach's Conjecture(哥达巴赫猜想)
生活随笔
收集整理的這篇文章主要介紹了
题目1440:Goldbach's Conjecture(哥达巴赫猜想)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:http://ac.jobdu.com/problem.php?pid=1440
?
詳解鏈接:https://github.com/zpfbuaa/JobduInCPlusPlus
?
參考代碼:
// // 1440 Goldbach's Conjecture.cpp // Jobdu // // Created by PengFei_Zheng on 12/04/2017. // Copyright ? 2017 PengFei_Zheng. All rights reserved. // #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <cmath>using namespace std;bool isPrime(long long n){// here n is no less than 4, so we don't need to consider 2、3long long x = sqrt(n)+1;for(long long i = 2 ; i <= x ; i ++){if(0 == n % i) return false;}return true; }long long n;int main(){while(scanf("%lld",&n)!=EOF && n!=0){int counter = 0;// beacuse n is even, so 2 can never being included// in order to reduce the calculation numbers, just need to reverse to n/2// therefore start with 3 and i+=2for(int i = 3 ; i <= n/2 ; i+=2){if(isPrime(i) && isPrime(n-i)){counter++;}}printf("%d\n",counter);}return 0; } /**************************************************************Problem: 1440User: zpfbuaaLanguage: C++Result: AcceptedTime:40 msMemory:1532 kb ****************************************************************/?
轉載于:https://www.cnblogs.com/zpfbuaa/p/6701440.html
總結
以上是生活随笔為你收集整理的题目1440:Goldbach's Conjecture(哥达巴赫猜想)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Day10:捡烟蒂投资法:便宜组合
- 下一篇: 解决方案 | 解决Adobe Acrob