YAPTCHA

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2041 Accepted Submission(s): 1047

Problem Description

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).

The task that is presented to anyone visiting the start page of the math department is as follows: given a natural n, compute

where [x] denotes the largest integer not greater than x.

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

设P=3K+7即可,每当p是素数,值就加一完事了

#include <algorithm>
#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;
//const ll mod=1e9+7;
bool pri[3000036];int s[1000036];
int main()
{
for(int i=0;i<3000010;i++)
pri[i]=true;
for(int i=2;i*i<3000010;i++)
if(pri[i])
for(int j=i*i;j<3000010;j+=i)
pri[j]=false;
s[1]=0;
for(int i=12,j=2;i<=3000010;i+=3,j++)
{
if(pri[i+1])
s[j]=s[j-1]+1;
else
s[j]=s[j-1];
}
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
printf("%d\n",s[n]);
}
}```

HDU2937 YAPTCHA(威尔逊定理)的更多相关文章

  1. hdu 2973"YAPTCHA"(威尔逊定理)

    传送门 题意: 给出自然数 n,计算出 Sn 的值,其中 [ x ]表示不大于 x 的最大整数. 题解: 根据威尔逊定理,如果 p 为素数,那么 (p-1)! ≡ -1(mod p),即 (p-1)! ...

  2. HDU 2973 YAPTCHA (威尔逊定理)

    YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. hdu2973 YAPTCHA【威尔逊定理】

    <题目链接> 题目大意: The task that is presented to anyone visiting the start page of the math departme ...

  4. YAPTCHA UVALive - 4382(换元+威尔逊定理)

    题意就是叫你求上述那个公式在不同N下的结果. 思路:很显然的将上述式子换下元另p=3k+7则有 Σ[(p-1)!+1/p-[(p-1)!/p]] 接下来用到一个威尔逊定理,如果p为素数则 ( p -1 ...

  5. HDU - 2973:YAPTCHA (威尔逊定理)

    The math department has been having problems lately. Due to immense amount of unsolicited automated ...

  6. HDU2973(威尔逊定理)

    YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  7. hdu2973-YAPTCHA-(欧拉筛+威尔逊定理+前缀和)

    YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  8. hdu5391 Zball in Tina Town(威尔逊定理)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Zball in Tina Town Time Limit: 3000/1500 ...

  9. HDU 5391 Zball in Tina Town【威尔逊定理】

    <题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care ...

随机推荐

  1. VSCode——自定义VSCode背景图片

    本文转载自https://blog.csdn.net/yukinoai/article/details/84564949 1.以管理员身份运行VS Code,安装background插件 2.打开se ...

  2. Java第十三天,内部类

    内部类 一.①成员内部类.②局部内部类(包含③匿名内部类) 1.内部类用外部类属性和方法的时候,可以随意进行访问. 2.外部类用内部类属性和方法的时候,需要通过内部类对象访问. 3.在编译成class ...

  3. MySQL REPLACE INTO 的使用

    前段时间写游戏合服工具时出现过一个问题,源DB和目标DB角色表中主键全部都不相同,从源DB取出玩家数据再使用 replace into 写入目标DB中,结果总有几条数据插入时会导致目标DB中原有的角色 ...

  4. python3(四十)datetime timestamp str

    """时间处理 """ __author__on__ = 'shaozhiqi 2019/9/25' # !/usr/bin/env pyt ...

  5. CocoaPods应用于iOS项目框架管理方案

  6. Linux 下迁移 Nexus3

    Nexus3 的迁移过程还是非常简单,复制整个目录到新服务器,启动即可. 备份 在原来服务器上将 nexus3 整体目录备份即可. $ tar -zcvf nexus3.tar.gz nexus3/ ...

  7. Atlassian 系列软件安装(Crowd+JIRA+Confluence+Bitbucket+Bamboo)

    公司使用的软件开发和协作工具为 Atlassian 系列软件,近期需要从腾讯云迁移到阿里云环境,简单记录下安装和配置过程.(Atlassian 的文档非常详尽,过程中碰见的问题都可以找到解决办法.) ...

  8. php开发中如何判断 是否微信访问

    在开发中遇到了这样一个需求,仅允许在微信中访问,所以就要对微信浏览器访问进行判断,本篇博文讲述如何判断是否是微信访问. /** * 判断是否微信访问 * @return bool */ functio ...

  9. 5000+图片找到你喜欢的那个TA,Python爬虫+颜值打分

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 罗罗攀 PS:如有需要Python学习资料的小伙伴可以加点击下方链接 ...

  10. util.Date与sql.Date的异同以及相互转换

    Java中有两个Date类 一个是java.util.Date通常情况下用它获取当前时间或构造时间 另一个是java.sql.Date是针对SQL语句使用的,它只包含日期而没有时间部分 两个类型的时间 ...