YAPTCHA

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1885    Accepted Submission(s): 971

 

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


Sample Output


题目大意

给定一个整数n,求

题目分析

威尔逊定理:

当且仅当p为素数时,(p−1)!≡−1(mod p)

所以我们可以发现,如果这个3k+7为奇数,式子就等于1,否则就等于0

#include<bits/stdc++.h>

using namespace std;

const int N=;
long long a[N];
bool prime[N];
int i,n,j,x;
int main()
{
for(i=; i<N; i++)
{
if(i%==) prime[i]=false;
else prime[i]=true;
}
for(i=; i<=sqrt(N); i+=)
{
if(prime[i])
for(j=i+i; j<N; j+=i)
prime[j]=false;
}
for(i=;i<=;i++)
{
a[i]=a[i-];
if(prime[*i+])
a[i]++;
}
cin>>n;
for(i=;i<=n;i++)
{
cin>>x;
cout<<a[x]<<endl;
}
}

HDU 2973 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)To ...

  3. HDU2937 YAPTCHA(威尔逊定理)

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

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

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

  5. hdu2973 YAPTCHA【威尔逊定理】

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

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

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

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

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

  8. HDU 6608:Fansblog(威尔逊定理)

    Fansblog Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Subm ...

  9. HDU2973(威尔逊定理)

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

随机推荐

  1. qt5---QMainWindow

    QMainWindow是一个为用户提供主窗口程序的类,包含一个菜单栏(menu bar).多个工具栏(tool bars).多个锚接部件(dock widgets)[就是浮动窗口].一个状态栏(sta ...

  2. Tomcat非root身份运行制作Linux系统服务管理

    理论知识怱略,马上开始实战 一.首先准备好tomcat 启动.关闭.重启Shell脚本: 以下Shell脚本主要修改值 tomcatPath:tomcat目录 runUser:以哪个身份运行 此处测试 ...

  3. 《剑指offer》算法题第四天

    今日题目: 二进制中1的个数 数值的整数次方 调整数组顺序使奇数位于偶数前面 链表中倒数第K个节点 链表中环的入口节点 今天的题目都比较简单,但是前三道题都有不同的解法,4,5两题就不在这边讨论了,其 ...

  4. BZOJ 3784: 树上的路径 点分治+二分+set

    很容易想出二分这个思路,但是要想办法去掉一个 $log$. 没错,空间换时间. 双指针的部分错了好几次~ Code: #include <set> #include <queue&g ...

  5. Codeforces 622F The Sum of the k-th Powers ( 自然数幂和、拉格朗日插值法 )

    题目链接 题意 : 就是让你求个自然数幂和.最高次可达 1e6 .求和上限是 1e9 分析 :  题目给出了最高次 k = 1.2.3 时候的自然数幂和求和公式 可以发现求和公式的最高次都是 k+1 ...

  6. vue的基础数据绑定

    todo https://www.jb51.net/article/132344.htm

  7. [CSP-S模拟测试]:组合(欧拉路)

    题目传送门(内部题119) 输入格式 第一行,三个整数$T,M,N$. 接下来的$N$行,每行两个整数$u_i,v_i$($i$从$1$开始编号).允许$u_i=v_i$,也允许同样的简单词多次出现. ...

  8. What’s up with the Graph Laplacian

    What's up with the Graph Laplacian? 来源 作者:Jeremy Kun blog: Math ∩ Programming 在数学上图和与图关联的某些矩阵的代数性质有很 ...

  9. ArrayList类源码浅析(三)

    1.看一个示例 运行上述代码,抛出一个异常: 这是一个典型的并发修改异常,如果把上述代码中的125行注释,把126行打开,运行就能通过了: 原因: 1)因为在迭代的时候,使用的是Itr类的对象,在调用 ...

  10. MyBatis中的JdbcType映射介绍

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.                                               本 ...