00-自测2. 素数对猜想 (20)

</pre></div></div></div><div id="problemInfo" class="rfloat" style="margin: 0px; padding: 2px; border: 1px solid rgb(221, 221, 221); font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; font-size: 12px; line-height: 18px; vertical-align: baseline; float: right; text-align: center; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);"><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">时间限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;">400 ms</div></div><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">内存限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;">65536 kB</div></div><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">代码长度限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;">8000 B</div></div><div class="checker" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">判题程序</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;"><span title="纯文本对比" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;">Standard</span></div></div><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">作者</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;">CHEN, Yue</div></div><div id="problemContent" style="margin: 0px; padding: 0px; border: 0px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; font-size: 12px; line-height: 18px; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);"><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;">让我们定义 d<sub style="line-height: 0;">n</sub> 为:d<sub style="line-height: 0;">n</sub> = p<sub style="line-height: 0;">n+1</sub> - p<sub style="line-height: 0;">n</sub>,其中 p<sub style="line-height: 0;">i</sub> 是第i个素数。显然有 d<sub style="line-height: 0;">1</sub>=1 且对于n>1有 d<sub style="line-height: 0;">n</sub> 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;">现给定任意正整数N (< 10<sup style="line-height: 0;">5</sup>),请计算不超过N的满足猜想的素数对的个数。</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;"><strong>输入格式:</strong>每个测试输入包含1个测试用例,给出正整数N。</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; line-height: inherit; vertical-align: baseline;"><strong>输出格式:</strong>每个测试用例的输出占一行,不超过N的满足猜想的素数对的个数。</p><strong>输入样例:</strong><pre style="margin-top: 1.5em; margin-bottom: 1.5em; padding: 0px; border: 0px; font-family: 'Droid Sans Mono', Consolas, 'Courier New', monospace; font-size: 1em; line-height: 1.5; vertical-align: baseline; overflow: auto;">20
输出样例:
4
#include <iostream>
#include <math.h>
#define MAX 100000
using namespace std;


bool isPrime(int n)
{
    if(n==2||n==3)
        return true;
   for(int i=2;i<=sqrt(n);i++)
    if(n%i==0)
        return false;
   return true;
}


int a[10001];
int main()
{
    int i,j=1,N;
    a[0]=2;a[1]=3;
    cin>>N;
    int sum=0;
    for(i=3;i<=N-2;)
    {
        if(isPrime(i)&&isPrime(i+2))
        {
            sum++;
        }
        i+=2;
    }
    cout<<sum<<endl;
    return 0;
}


 
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值