HDU 2973 YAPTCHA (威尔逊定理)
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
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
Output
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 (威尔逊定理)的更多相关文章
- hdu 2973"YAPTCHA"(威尔逊定理)
传送门 题意: 给出自然数 n,计算出 Sn 的值,其中 [ x ]表示不大于 x 的最大整数. 题解: 根据威尔逊定理,如果 p 为素数,那么 (p-1)! ≡ -1(mod p),即 (p-1)! ...
- HDU - 2973 - YAPTCHA
先上题目: YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU2937 YAPTCHA(威尔逊定理)
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- HDU - 2973:YAPTCHA (威尔逊定理)
The math department has been having problems lately. Due to immense amount of unsolicited automated ...
- hdu2973 YAPTCHA【威尔逊定理】
<题目链接> 题目大意: The task that is presented to anyone visiting the start page of the math departme ...
- 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 6608:Fansblog(威尔逊定理)
Fansblog Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Subm ...
- HDU2973(威尔逊定理)
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
随机推荐
- 树莓派设定笔记(Raspberry Pi 3 B+)
树莓派默认用户名密码 pi / raspberry 一.启用root用户 设置root用户密码 sudo passwd root 开启root账户 sudo passwd --unlock root ...
- Python 文件I/OⅢ
read()方法 read()方法从一个打开的文件中读取一个字符串.需要重点注意的是,Python字符串可以是二进制数据,而不是仅仅是文字. 语法: 在这里,被传递的参数是要从已打开文件中读取的字节计 ...
- <label>标签的相关内容
㈠<label>标签的定义与用法 ⑴<label> 标签为 input 元素定义标注(标记). ⑵label 元素不会向用户呈现任何特殊效果.不过,它为鼠标用户改进了可用性.如 ...
- cp:复制文件和目录
cp 命令,主要用来复制文件和目录,同时借助某些选项,还可以实现复制整个目录,以及比对两文件的新旧而予以升级等功能. cp 命令的基本格式如下:cp [选项] 源文件 目标目录/文件 选项: -a:相 ...
- (Java多线程系列三)线程间通讯
Java多线程间通讯 多线程之间通讯,其实就是多个线程在操作同一个资源,但是操作的动作不同. 1.使用wait()和notify()方法在线程中通讯 需求:第一个线程写入(input)用户,另一个线程 ...
- C++入门经典-例3.20-使用continue跳出循环
1:continue不是立即跳出循环体,而是跳过本次循环结束前的语句,回到循环的条件测试部分.代码如下: // 3.20.cpp : 定义控制台应用程序的入口点. // #include " ...
- [翻译]扩展C#中的异步方法
翻译自一篇博文,原文:Extending the async methods in C# 异步系列 剖析C#中的异步方法 扩展C#中的异步方法 C#中异步方法的性能特点. 用一个用户场景来掌握它们 在 ...
- oj.1677矩形嵌套,动态规划 ,贪心
#include<iostream> #include<algorithm> #include<cstring> using namespace std; stru ...
- 【Spark机器学习速成宝典】模型篇01支持向量机【SVM】(Python版)
目录 支持向量机原理 支持向量机代码(Spark Python) 支持向量机原理 详见博文:http://www.cnblogs.com/itmorn/p/8011587.html 返回目录 支持向量 ...
- 通过daemon.json配置docker 2375 API端口,配置私有http仓库
编辑daemon.json vi /etc/docker/daemon.json 配置如下内容即可 { "hosts":[ "tcp://0.0.0.0:2375&quo ...