题目链接: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. Linux系统教程:设置GRUB菜单密码

    1.认识启动配置选项 [root@server5 ~]# cat /boot/grub/grub.conf     # grub.conf generated by anaconda # # Note ...

  2. 每天一个linux命令:cat 命令

    cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 1.命令格式: cat [选项] [文件] ...

  3. C# 获取文件夹下的所有文件的文件名

    String path = @"X:\xxx\xxx"; //第一种方法 var files = Directory.GetFiles(path, "*.txt" ...

  4. windows版mysql配置--my.ini

    完整配置如下: # power by phpStudy 2014 www.phpStudy.net 官网下载最新版 [client] port=3306 [mysql] [mysqld] port=3 ...

  5. Mac eclipse 连接安卓手机调试 adb

    echo 手机厂商号 >>  ~/.android/adb_usb.ini  ~ echo 0x18d1 >>  ~/.android/adb_usb.ini 重启系统即可 环 ...

  6. 限制 Text Field 输入的内容类型:只允许输入数字

    效果如下: ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController< ...

  7. SCXcodeSwitchExpander自动填充switch语句下枚举类型case

    下载地址:https://github.com/stefanceriu/SCXcodeSwitchExpander 跟VVDocumenter规范注释生成器的安装方式一样: 下载开源工程在Xcode重 ...

  8. WebGL Matrix4(4*4矩阵库)

    Matrix4是由<<WebGL编程指南>>作者写的提供WebGL的4*4矩阵操作的方法库,简化我们编写的代码.源代码共享地址,点击链接:Matrix4源代码. 下面罗列了Ma ...

  9. css抠图之background-position-背景定位

    相信很多喜欢研究网页界面的童鞋都遇到过一个奇妙的现象:网页中很多图片素材被合成在一张图片上. 其实,这是一个非常简单的技术. 要想实现CSS抠图,只需要用到一个属性:background-positi ...

  10. SQL 语句判断记录是否存在(最简洁简单性能最优)

    今天查了下,发现网上的没有一个sql语句写的好的. 判断记录是否存在,要不是语句不够简洁,要不就是性能有很大问题. 我进行了优化后,最简洁简单性能最优的的sql语句,用来判断表中的记录是否存在: se ...