题目链接: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、3
long long x = sqrt(n)+;
for(long long i = ; i <= x ; i ++){
if( == n % i) return false;
}
return true;
} long long n; int main(){
while(scanf("%lld",&n)!=EOF && n!=){
int counter = ;
// 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+=2
for(int i = ; i <= n/ ; i+=){
if(isPrime(i) && isPrime(n-i)){
counter++;
}
}
printf("%d\n",counter);
}
return ;
}
/**************************************************************
Problem: 1440
User: zpfbuaa
Language: C++
Result: Accepted
Time:40 ms
Memory:1532 kb
****************************************************************/

题目1440:Goldbach's Conjecture(哥达巴赫猜想)的更多相关文章

  1. 1968: C/C++经典程序训练6---歌德巴赫猜想的证明

    1968: C/C++经典程序训练6---歌德巴赫猜想的证明 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 1165  Solved: 499[Submi ...

  2. poj-2909-哥德巴赫猜想

    Description For any even number n greater than or equal to 4, there exists at least one pair of prim ...

  3. 问题 C: Goldbach's Conjecture

    题目描述 Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least ...

  4. Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】

    Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...

  5. UVa 543 - Goldbach's Conjecture

    题目大意:给一个偶数,判断是否是两个素数的和. 先用sieve方法生成一个素数表,然后再进行判断即可. #include <cstdio> #include <vector> ...

  6. POJ 2262 Goldbach's Conjecture (打表)

    题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...

  7. F - Goldbach`s Conjecture 对一个大于2的偶数n,找有多少种方法使两个素数的和为n;保证素数a<=b; a+b==n; a,b都为素数。

    /** 题目:F - Goldbach`s Conjecture 链接:https://vjudge.net/contest/154246#problem/F 题意:对一个大于2的偶数n,找有多少种方 ...

  8. poj 2262 Goldbach's Conjecture——筛质数(水!)

    题目:http://poj.org/problem?id=2262 大水题的筛质数. #include<iostream> #include<cstdio> #include& ...

  9. Poj 2662,2909 Goldbach's Conjecture (素数判定)

    一.Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard ...

随机推荐

  1. HttpURLConnection和HttpClient的区别2(转)

    1.HttpClient比HttpURLConnection功能更强大,但是做java建议用前者,安卓建议用后者 2.这两者都支持HTTPS,streaming 上传与下载,配置超时时间,IPv6,  ...

  2. 机器学习结果加ID插入数据库源码

    import org.apache.spark.mllib.evaluation.BinaryClassificationMetrics import org.apache.spark.mllib.l ...

  3. localstorage和sessionstorage上手使用记录

    通过阅读各路大神对web存储locastorage和sessionstorage的用法解析,自己试用了一下,在此留个备忘. 在项目中,如果用到很多次storage,要存储很多数据,就要把它封装成函数了 ...

  4. 在jstl表达式中嵌入el表达式

    一.问题 在jsp中,想要这么写: <c:url value='/resources/themes/${easyuiThemeName}/easyui.css'/> 但报错:Accordi ...

  5. Python集成开发环境PyCharm调试

    Run/Debug配置: 设置断点:在行号后单击(再单击取消) 启动调试:Shift+F9 单步执行:F8 进入函数:F7 跳出函数:Shift+F8 运行到下一个断点:F9 调试中查看: 退出调试: ...

  6. linux环境中nagios(nagios core)安装?nagios安装?

    需求描述: 最近准备给线上生产环境部署监控平台,对各个系统的资源使用情况,服务进行监控,采用nagios core版本进行部署, nagios core是开源版本的软件,是免费的nagios XI是上 ...

  7. GOF---Java开发中的23种设计模式详解

    表点 设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式 ...

  8. IIS日志清理(VBS版,JS版)

    IIS默认日志记录在C:\WINDOWS\system32\LogFiles,时间一长,特别是子站点多的服务器,一个稍微有流量的网站,其日志每天可以达到上百兆,这些文件日积月累会严重的占用服务器磁盘空 ...

  9. 执行RF测试只生成output.xml文件,不生成log和report文件

    命令格式: -l --log file HTML log file. Can be disabled by giving a special value `NONE`. Default: log.ht ...

  10. Redis 操作有序集合数据

    Redis 操作有序集合数据: > zadd names "Tom" // zadd 用于往有序集合中添加元素,其中 1 在 Redis 中称为 score(分数),用来进行 ...