威尔逊定理--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 ...
随机推荐
- 09 Finding a Motif in DNA
Problem Given two strings ss and tt, tt is a substring of ss if tt is contained as a contiguous coll ...
- Text Relatives
[Text Relatives] With TextKit the resources at your disposal range from framework objects—such as te ...
- Java线程死锁查看分析方法
如何查看是否有Java线程死锁?下面介绍两种方法. 一.Jconsole Jconsole是JDK自带的图形化界面工具,使用JDK给我们的的工具JConsole,可以通过打开cmd然后输 ...
- 懒人的ERP开发框架--2B&苦B程序员专用
在企业内部的ERP系统开发中,如果使用MS的技术,那么Winform + DevExpress + IIS + WCF +EF 就是懒人的黄金组合了,EF使用数据库优先,一般ERP应用主要关注点在数据 ...
- Oracle查看字符集
select * from nls_database_parameters where parameter like 'NLS%CHARACTERSET';
- 如何用word文档在博客里发表文章
目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...
- (博弈 sg入门2)
接下来介绍Nim游戏(同样引用杭电上的,懒的打字) 1.有两个玩家: 2. 有三堆扑克牌(比如:可以分别是 5,7,9张): 3. 游戏双方轮流操作: 4. 玩家的每次操作是选择其中某 ...
- .NET 匿名方法的BUG,请专家解答
匿名方法是.NET 3.5之后的一个好东东,很多人使用,但是我在最近的工作当中发现了一个问题. 请专家解答 //list里存放10个数字 List<); ; i < ; i++) { li ...
- 3:C#异步WaitAll的使用
编写界面如图: private async void button1_Click(object sender, EventArgs e) { #region 单个执行的异步,效率慢 HttpClien ...
- Django博客项目思路整理
首先明确一点,我目前学习Django是为了做一个博客,那么以博客为目标进行实践的话,按照Django的MTV模型的顺序来思考的话,要考虑如下几个事情: (Models) 1.在博客里的各种数据模型: ...