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. wx小程序知识点(三)

    三.封装小程序的数据请求 (1)在根目录创建utils目录,创建config.js.base.js (2)在config.js中创建config类,并将请求路径配置给config的属性restUrl, ...

  2. linux 能ping通IP但无法解析域名

    vi /etc/nsswitch.conf hosts: files dns networks: files 改成: hosts: files dns wins networks: files 最近碰 ...

  3. HTML DOM 事件与方法

    HTML DOM 事件允许Javascript在HTML文档元素中注册不同事件处理程序. 事件通常与函数结合使用,函数不会在事件发生前被执行! (如用户点击按钮). 鼠标事件 键盘事件 框架/对象(F ...

  4. HGOI20190706 题解

    Problem A 质因数 设f(x) 表示x的不同质因子个数,给出T组x,询问f(x)的值. 对于100%的数据 $x,T \leq 10^5 $ Sol : 第一遍欧拉筛,并记录下每个数的最小质因 ...

  5. JDK_API剖析之java.io包

    Java的核心库java.io提供了全面的IO接口.包括:文件读写.标准设备输出等.Java中IO是以流为基础进行输入输出的,所有数据被串行化写入输出流,或者从输入流读入. 一.接口 1.Closea ...

  6. 10.Python内置函数一览表

    为了提高程序员的开发效率,Python 提供了很多可以直接拿来用的函数(初学者可以先理解为方法),每个函数都可以帮助程序员实现某些具体的功能. 举个例子,在 Python 2.x 中 print 只是 ...

  7. Mongo Cursor

    简介 在使用 Java 对数据库进行连接时,都会获取到一个 cursor ,cursor 实际指到的是我们查询数据库的query,而并不是 query 查询到的数据集. 此次在使用 mongo 的 c ...

  8. Spring boot之Hello World访问404

    (1)404 -- 确定地址是否输入正确,,此路径非彼路径 (2)404 -- 是否用对注解,此注解非彼注解 (3)404 -- 包路径是否正确,此包非彼包 (4)404 -- 确认类包是否正确,此类 ...

  9. React 开发中面临的九个重要抉择

    抉择系列:在技术开发的过程中我们会面临着各种各样的抉择,我们在不同情境下该如何选择恰当的技术,这是本系列文章想要解决的问题. 在 React 开发的过程中我们常常会遇到一些抉择,下面我将选取其中一些个 ...

  10. python3笔记一:python基础知识

    一:学习内容 注释 输入输出 标识符 变量和常量 二:注释 1. 单行注释 #:一个井号,代表我注释了这一行 2.多行注释 ''' ''':注释多行,三个单引号 3.多行注释 "" ...