题目链接: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. 前端Table数据导出Excel使用HSSFWorkbook(Java)

    一.实现原理: 1. 前端查询列表数据并渲染至table(<table>...</table>)表格 2. 表格html代码传输至后台 3. 后台把html转成Excel输出流 ...

  2. “A configuration with this name already exists” error in eclipse run configurations

    “A configuration with this name already exists” error in eclipse run configurations Is there a way t ...

  3. Redis锁的简单应用

    本文版权归博客园和作者本人吴双共同所有 .转载爬虫请注明地址,博客园蜗牛 http://www.cnblogs.com/tdws/p/5712835.html 蜗牛Redis系列文章目录http:// ...

  4. hibernate.cfg配置mysql方言

    hibernate自动建表,mysql高版本不支持 type=InnoDB 中的type关键字. 应该使用engine关键字 而非type 所以需要在hibernate.cfg.xml中配置方言.否则 ...

  5. vue v-if与v-show使用注意问题

    在使用中发现v-show和v-if用哪个都不可以控制元素块的显示隐藏, 之前v-show和v-if都是这样写的: <span v-if="{loadingComplete:false} ...

  6. python-类的方法与类的成员

    preface include: @classmethod @staticmethod @property 私有属性 类的成员 #!/usr/bin/env python class animal(o ...

  7. [Err] 1231 - Variable 'sql_mode' can't be set to the value of 'NULL

    在MYSQL还原语句的时候,报: [Err] - Variable 'sql_mode' can't be set to the value of 'NULL 解决办法:打开SQL语句,把里面的注释给 ...

  8. MVC输出字符串常用四个方式

    "); ";//@Html.Raw(s1); "); ";//@String.fomart(s3); 要MVC的Razor视图输出字符串的常用几个方式 记录下 ...

  9. mysql数据库2

    命令行客户端软件MySQL Command Line Client, 打开该程序,输入数据库密码,登陆到MySQL软件, 如果想通过该命令行工具来操作MySQL软件,只需要在"mysql&g ...

  10. event.keyCode与event.which

        //Netscape/Firefox/Opera中不支持 window.event.keyCode,需要用event.which代替//IE用event.keCode方法获取当前被按下的键盘按 ...