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 ...
随机推荐
- CSS3的多列属性
CSS3 可以将文本内容设计成像报纸一样的多列布局 ㈠CSS3 多列属性 ㈡column-count 属性 ⑴语法:column-count: number|auto; ⑵值: ㈢c ...
- Linux命令-文件管理(一)
Linux命令-文件管理(一) 1.命令:cat cat命令用于把档案串连接后传到基本输出(萤幕或加 > fileName 到另一个档案) 使用权限:所有使用者 语法格式:cat [-AbeEn ...
- Java 工程师成神之路
基础篇 → 什么是面向对象 面向对象.面向过程 是一种新兴的程序设计方法,或者是一种新的程序设计规范(paradigm),其基本思想是使用对象.类.继承.封装.多态等基本概念来进行程序设计.从现实世界 ...
- python学习之路(12)
迭代 如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration). 在Python中,迭代是通过for ... in来完成的,而 ...
- 添加一个静态JAVA库
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Build all java files in the java subdirectory L ...
- springboot 项目中在普通类中调用dao层的mapper 出现空指针异常
项目中我遇到同样的问题 特记载一下 有两种方式 一. 该类使用@Component注解 添加一个本类类型的静态字段 创建一个初始化方法,贴上@PostConstruct 标签,用于注入bean 创建方 ...
- LeetCode 14. 最长公共前缀(Longest Common Prefix)
题目描述 编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower","flow ...
- SpringBoot中application.yml基本配置详情
把原有的application.properties删掉.然后 maven -X clean install,或者通过Maven Project双击clean和install(1)端口服务配置 #端口 ...
- 乌班图docker版本18.04升级到19.03
# 关闭docker sudo systemctl stop docker # 卸载旧版本: sudo apt-get purge docker-ce # 安装新版本 sudo apt update ...
- 搭建jenkins集群node结点
配置结点 首先,需要在jenkins的系统设置中新增一个结点 系统管理 -> 节点管理 -> New Node 配置Remote root directory最好和主jenkins的路径一 ...