威尔逊定理--HDU2973
题目
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)为素数时,a_n为1,否则为0
\]
代码
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e6+5;
const double pi = acos(-1);
const int mod=1e9+7;
const int N = 1000005;
int vis[N * 4], p[N * 4];
int ans[N];
void Init()\\埃式筛
{
for(int i = 2;(i - 7) / 3 < N;++i)
{
if(!vis[i])
{
if((i - 7) % 3 == 0)
p[(i - 7) / 3] = 1;
for(int j = i + i;j <= N * 4;j += i)
vis[j] = true;
}
}
for(int i = 1;i < N;++i)
ans[i] = ans[i - 1] + p[i];
}
int main()
{
Init();
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
cout << ans[n] << endl;
}
return 0;
}
[素数定理](https://en.wikipedia.org/wiki/Dirichlet's_theorem_on_arithmetic_progressions)
当a、b为素数时,则形如 a+nb 的素数有无穷多个
威尔逊定理--HDU2973的更多相关文章
- HDU2973(威尔逊定理)
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- hdu2973 YAPTCHA【威尔逊定理】
<题目链接> 题目大意: The task that is presented to anyone visiting the start page of the math departme ...
- hdu2973-YAPTCHA-(欧拉筛+威尔逊定理+前缀和)
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu5391 Zball in Tina Town(威尔逊定理)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Zball in Tina Town Time Limit: 3000/1500 ...
- hdu 2973"YAPTCHA"(威尔逊定理)
传送门 题意: 给出自然数 n,计算出 Sn 的值,其中 [ x ]表示不大于 x 的最大整数. 题解: 根据威尔逊定理,如果 p 为素数,那么 (p-1)! ≡ -1(mod p),即 (p-1)! ...
- HDU 5391 Zball in Tina Town【威尔逊定理】
<题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care ...
- YAPTCHA UVALive - 4382(换元+威尔逊定理)
题意就是叫你求上述那个公式在不同N下的结果. 思路:很显然的将上述式子换下元另p=3k+7则有 Σ[(p-1)!+1/p-[(p-1)!/p]] 接下来用到一个威尔逊定理,如果p为素数则 ( p -1 ...
- HDU - 2973:YAPTCHA (威尔逊定理)
The math department has been having problems lately. Due to immense amount of unsolicited automated ...
- HDU6608-Fansblog(Miller_Rabbin素数判定,威尔逊定理应用,乘法逆元)
Problem Description Farmer John keeps a website called ‘FansBlog’ .Everyday , there are many people ...
随机推荐
- http头部信息
1.常见的返回码 100: 请服务器端继续返回 200:成功 301:永久重定向 存的地址永久的改变了 301 302 : 暂时重定向 302仍然使用老得url 401 : 无法找到资源file n ...
- Android Studio真机测试
本页内容 1.真机测试好处多 2.开始吧!真机测试 1.真机测试好处多 不久前才开我的Android Studio之旅,就遇上了一个大麻烦——创建的模拟器各种运行出错.尝试了各种解决方法,都没有什么结 ...
- 解决RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 Request Entity Too Large问题
使用SourceTree客户端,向远程仓库推送时:RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 Request ...
- 基于httpcore(httpclient component)搭建轻量级http服务器
下面是apache官网例子 服务器端接受请求,实现接收文件请求处理器 import java.io.File; import java.io.IOException; import java.io.I ...
- Java动态代理(二)CGLIB动态代理应用
JDK自从1.3版本开始,就引入了动态代理,JDK的动态代理用起来非常简单,但是它有一个限制,就是使用动态代理的对象必须实现一个或多个接口 .如果想代理没有实现接口的类可以使用CGLIB包. CGLI ...
- [label][WorldPress] 一个很方便查找定位WorldPress源代码位置的网址
作为 WordPress 的新手,根本不熟悉那些函数究竟是什么作用的,所以就必须要去看源代码. 要去查看源代码,那么你就必须要熟悉 WordPress 下面文件的作用,以及那个文件中定义了有哪些函数? ...
- 点滴笔记(二):利用JS对象把值传到后台
记得以前刚写asp.net 从前台往后台传值 都是var data=A,B,C,D,E; 循环添加用逗号隔开 后台还要被测试测出只输入,就错了 哈哈..后来用✈◆类似的符号隔开 不是长久之计... 现 ...
- WINSOCK网络函数
1. 头文件及库文件 头文件:WINSOCK2.H 库:WS2_32.LIB库 如果是在WINCE中,不支持SOCK2,所以: 头文件:WINSOCK.H 库:WSOCK32.LIB 如果从MSWSO ...
- Linq中的group by多表多字段
在sql中,如果有group by,那么select的字段只能包含分组内容,或者count.sum.avg这些统计字段. 但在linq里面,是:group 你想要什么字段 by 分组字段 比如: va ...
- SQLServer数据库的状态一直都是正在还原
解决方案: 执行以下SQL语句 restore database [数据库名称] with recovery