威尔逊定理B

威尔逊定理B题目 Themathdepar Duetoimmense theydecidedt Another Public Turing Te

题目

The math department has been having problems lately. Due to immense amount of unsolicited automated programs which were crawling across their pages, they decided to put Yet-Another-Public-Turing-Test-to-Tell-Computers-and-Humans-Apart on their webpages. In short, to get access to their scientific papers, one have to prove yourself eligible and worthy, i.e. solve a mathematic riddle.

However, the test turned out difficult for some math PhD students and even for some professors. Therefore, the math department wants to write a helper program which solves this task (it is not irrational, as they are going to make money on selling the program).

Input
The first line contains the number of queries t (t ≤ 10^6). Each query consist of one natural number n (1 ≤n ≤10^6).

Output
For each n given in the input output the value of Sn.

Sample Input
13
1
2
3
4
5
6
7
8
9
10
100
1000
10000




























Sample Output
0
1
1
2
2
2
2
3
3
4
28
207
1609


























然而,对于一些数学博士生甚至一些教授来说,测试结果很难。 因此,数学系想要编写一个帮助程序来解决这个任务(这不是不合理的,因为他们会在出售程序时赚钱)。

代码如下:

#include 
     #include 
     #include 
     #include 
     using namespace std; const int mx=3e6+10; int s[mx]; int isprime[mx]; void init()//这里初始化,求出每个i对应的数字是否为素数,然后求和 { 
    memset(isprime,0,sizeof(isprime)); for(int i=2;i<mx;i++) { 
    if(!isprime[i])//最普通的埃氏筛法 { 
    for(int j=2*i;j<mx;j+=i) isprime[j]=1; } } memset(s,0,sizeof(s)); s[0]=0,s[1]=0; for(int i=2;i<=1e6;i++)//求和 { 
    int re=3*i+7; s[i]=s[i-1]+(1-isprime[re]); } } int main() { 
    int t,n; init(); scanf("%d",&t); while(t--) { 
    scanf("%d",&n); printf("%d\n",s[n]);//直接输出 } return 0; } 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/215630.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月18日 下午1:48
下一篇 2026年3月18日 下午1:48


相关推荐

  • mina框架详解

    mina框架详解From http blog csdn net w article details

    2026年3月17日
    2
  • 栈溢出

    栈溢出Author:Liedrahttps://www.cnblogs.com/LieDra/入门介绍学习自https://zhuanlan.zhihu.com/p/25816426对部分内容进行

    2022年7月4日
    28
  • mysql opkg源_OpenWrt opkg 在线源默认配置

    mysql opkg源_OpenWrt opkg 在线源默认配置destroot/destram/tmplists_dirext/var/opkg-listsoptionoverlay_root/overlaysrc/gzbarrier_breaker_basehttp://downloads.openwrt.org/barrier_breaker/14.07/x86/generic/packages/basesrc/gzbarrier_…

    2022年6月2日
    50
  • html常见的表单元素有哪些,html表单元素有哪些?

    html常见的表单元素有哪些,html表单元素有哪些?HTML 中常用的表单元素包括 文本区域 TEXTAREA 列表框 SELECT 文本输入框 INPUTtype text 密码输入框 INPUTtype password 单选输入框 INPUTtype radio 复选输入框 INPUTtype checkbox 重置按钮 提交按钮 隐藏域 等等 一 文本域二 密码域密码跟文本框类似 但是在里面输入的内容显示为圆点 三 单选按

    2026年3月17日
    2
  • C段与旁站

    C段与旁站旁站旁站指的是网站所在服务器上部署的其他网站旁注的意思就是从同台服务器上的其他网站入手 提权 然后把服务器端了 就自然把那个网站端了 C 段 C 段指的是例如 192 168 1 4 192 是 A 段 168 是 B 段 1 是 C 段 4 是 D 段 C 段嗅探指的是拿下同一 C 段下的服务器 也就是说是 D 段 1 255 中的一台服务器即 旁注 同服务器不同站点的渗透方案 C 段 同网段不同服务器的渗透方案

    2026年3月18日
    2
  • ubuntu clion 2020 永久激活码_通用破解码

    ubuntu clion 2020 永久激活码_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    182

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号