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 ...
随机推荐
- vue 中监听窗口发生变化,触发监听事件, window.onresize && window.addEventListener('resize',fn) ,window.onresize无效的处理方式
// 开始这样写,不执行 window.onresize = function() { console.log('窗口发生变化') } // 改成window监听事件 window.addEventL ...
- 文件操作:fopen()
r 打开只读文件,该文件必须存在. r+ 打开可读写的文件,该文件必须存在. rb+ 读写打开一个二进制文件,只允许读写数据. rt+ 读写打开一个文本文件,允许读和写. w 打开只写文件, ...
- 51 Nod 1627瞬间移动(插板法!)
1627 瞬间移动 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 关注 有一个无限大的矩形,初始时你在左上角(即第一行第一列),每次你都可以选择一个右 ...
- POJ 3352 Road Construction 中一个结论的证明
题面 分析: 很多人都给出了做法,在这里不赘述.大概就是先把桥找出来,然后边双缩点,最后统计新图上的度数.因为缩点后为一棵树,所以度数为1(即为叶子)的点的数目+1再除以2下取整就是答案. 这里主要证 ...
- mui 二维码扫描功能
mui 扫一扫识别二维码 以及多次扫码后从结果页返回时黑屏问题解决 扫一扫页面全部代码 <!doctype html><html> <head> ...
- 如何快速查询中科院JCR分区和汤森路透JCR分区
参考: https://blog.csdn.net/chichuhe/article/details/83054624 https://blog.csdn.net/Sunflower02/articl ...
- async/await 真不是你想象中那么简单
先上代码 公共代码 function getData(data, time) { return new Promise(function (resolve, reject) { setTimeout( ...
- 编译一个需要用特定key前面的应用程序
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Build all java files in the java subdirectory L ...
- C++入门经典-例5.3例5.4-输出int指针运算后的地址值
1:代码如下: // 5.3.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using ...
- MySQL中的exist与not exists
准备数据 我们先介绍下使用的3个数据表: student数据表: course数据表: sc数据表: EXISTS EXISTS代表存在量词∃.带有EXISTS谓词的子查询不返回任何数据,只产生逻辑真 ...