题目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、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(哥达巴赫猜想)的更多相关文章
- 1968: C/C++经典程序训练6---歌德巴赫猜想的证明
1968: C/C++经典程序训练6---歌德巴赫猜想的证明 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 1165 Solved: 499[Submi ...
- poj-2909-哥德巴赫猜想
Description For any even number n greater than or equal to 4, there exists at least one pair of prim ...
- 问题 C: Goldbach's Conjecture
题目描述 Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least ...
- Goldbach`s Conjecture(LightOJ - 1259)【简单数论】【筛法】
Goldbach`s Conjecture(LightOJ - 1259)[简单数论][筛法] 标签: 入门讲座题解 数论 题目描述 Goldbach's conjecture is one of t ...
- UVa 543 - Goldbach's Conjecture
题目大意:给一个偶数,判断是否是两个素数的和. 先用sieve方法生成一个素数表,然后再进行判断即可. #include <cstdio> #include <vector> ...
- POJ 2262 Goldbach's Conjecture (打表)
题目链接: https://cn.vjudge.net/problem/POJ-2262 题目描述: In 1742, Christian Goldbach, a German amateur mat ...
- 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,找有多少种方 ...
- poj 2262 Goldbach's Conjecture——筛质数(水!)
题目:http://poj.org/problem?id=2262 大水题的筛质数. #include<iostream> #include<cstdio> #include& ...
- Poj 2662,2909 Goldbach's Conjecture (素数判定)
一.Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard ...
随机推荐
- C# WinForm下,隐藏主窗体的方法
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- PS1-4
export PS2="continue->" cat ps4.sh export PS4='$0.$LINENO+ ' set -x echo "PS4 demo ...
- 深入解析Java AtomicInteger原子类型
深入解析Java AtomicInteger原子类型 在并发编程中,需要确保当多个线程同时访问时,程序能够获得正确的结果,即实现线程安全.线程安全性定义如下: 当多个线程访问一个类时,无论如何调度运行 ...
- Spring的JdbcTemplate与其事务
JdbcTemplate:http://lehsyh.iteye.com/blog/1579737 JdbcTemplate with TransactionTemplate:http://www.c ...
- MTK 隐藏上方的状态栏
步骤一: 源码/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.ja ...
- DotNetBar如何控制窗体样式
在C#中使用控件DevComponents.DotNetBar时,如何创建一个漂亮的窗口,并控制窗体样式呢? 1.新建一个DotNetBar窗体 2.使OFFICE窗口风格 ...
- Dubbo -- 系统学习 笔记 -- 示例 -- 泛化引用
Dubbo -- 系统学习 笔记 -- 目录 示例 想完整的运行起来,请参见:快速启动,这里只列出各种场景的配置方式 泛化引用 泛接口调用方式主要用于客户端没有API接口及模型类元的情况,参数及返回值 ...
- SpringMVC -- 梗概--源码--贰--上传
1.配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=&qu ...
- 10 -- 深入使用Spring -- 5... 实现任务的自动调度
10.5 实现任务的自动调度 10.5.1 使用Quartz 10.5.2 在Spring中使用Quartz
- Bypass 360主机卫士SQL注入防御(多姿势)
0x00 前言 在服务器客户端领域,曾经出现过一款360主机卫士,目前已停止更新和维护,官网都打不开了,但服务器中依然经常可以看到它的身影.从半年前的测试虚拟机里面,翻出了360主机卫士Apache版 ...