威尔逊定理--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 ...
随机推荐
- SOAP与REST比较(转)
出处:http://xiaobaila.blog.163.com/blog/static/189705129201141965434571/ SOAP与REST比较 如今,Web开发者的可选技术相当之 ...
- DevExpress,LayoutControl,TreeList,GridControl等
1.显示边框进行折叠 选择一个layoutControlGroupX 将其GroupBordersVisible设置成True,将TextVisiable=True 2. TreeList 2.1需要 ...
- webapi Model Validation 模型验证
通常情况下,对于那些经常为别人提供数据接口的开发人员来说,对于调用方传递过来的参数都会有验证处理.例如: if (string.IsNullOrEmpty(entity.Name)) { //当姓名为 ...
- 原型模式及C++实现
以下是我自己学习设计模式的感想. 原型模式 学过C++的都知道拷贝构造函数,复制一个对象分为浅拷贝和深拷贝. 浅拷贝:就是给对象中的每个成员变量进行复制,就是把A1类中的变量直接赋给A2类中变量,属于 ...
- POJ3281 Dining 2017-02-11 23:02 44人阅读 评论(0) 收藏
Dining Description Cows are such finicky eaters. Each cow has a preference for certain foods and dri ...
- 微信公众开发URL和token填写详解
微信公众开发URL和token填写详解 方法/步骤 作为一名微信公众号开发者,别人进入你的微信公众号,肯定会看见某些网页,或者给你发某些信息,你需要实时自动回复,所以你需要一个24小时为用户服 ...
- HTML解析器软件
HTML解析器软件 HTML文档解析器 HTMLParser HTML Parser 是一个对HTML进行分析的快速实时的解析器,最新的发行版本是1.6,另外2.0的开发版本已经两年没有进展了.示例代 ...
- js 倒计时,转义
function leftTimer(time) { var leftTime = (new Date(time)) - (new Date()); //计算剩余的毫秒数 var days = par ...
- asp.net mvc部分视图的action中获取父级视图信息
RouteData.DataTokens["ParentActionViewContext"]中包含了父级视图的相关信息,如路由等 public ActionResult Chil ...
- RoadFlow ASP.NET Core工作流引擎IIS部署
RoadFlow最新版本采用ASP.NET CORE2.1开发,部署步骤和.NET CORE部署一样,具体可参数ASP.NET CORE的部署方式. 1. 获取代码 首先从RoadFlow官网下载最新 ...