HDU - 2973 - YAPTCHA
先上题目:
YAPTCHA
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 463 Accepted Submission(s): 280
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.
first line contains the number of queries t (t <= 10^6). Each query
consist of one natural number n (1 <= n <= 10^6).
1
2
3
4
5
6
7
8
9
10
100
1000
10000
#include <stdio.h>
#include <string.h>
#define MAX 1000110
using namespace std; bool pri[MAX*];
int ans[MAX]; void dedeal()
{
long long i,j,n;
n=(MAX-)*;
memset(pri,,sizeof(pri));
pri[]=pri[]=;
for(i=;i<=n;i++)
{
if(!pri[i])
for(j=i*i;j<=n;j+=i) pri[j]=;
}
} void deal()
{
int i,n;
n=(MAX-);
memset(ans,,sizeof(ans));
for(i=;i<=n;i++)
{
if(!pri[*i+])
ans[i]=ans[i-]+;
else ans[i]=ans[i-];
}
} int main()
{
int n,t;
//freopen("data.txt","r",stdin);
dedeal();
deal();
scanf("%d",&t);
while(t--)
{
scanf("%d\n",&n);
printf("%d\n",ans[n]);
}
return ;
}
2973
提速版
#include <iostream>
#include <string.h>
#include <stdio.h>
#define MAX 1000110
using namespace std ;
bool pri[] ;
int ans[] ; void dedeal()
{
long long i,j,n;
n=(MAX-)*;
memset(pri,,sizeof(pri));
pri[]=pri[]=;
for(i=;i<=n;i++)
{
if(!pri[i])
for(j=i*i;j<=n;j+=i) pri[j]=;
}
} void deal()
{
int i,n;
n=(MAX-);
memset(ans,,sizeof(ans));
for(i=;i<=n;i++)
{
if(!pri[*i+])
ans[i]=ans[i-]+;
else ans[i]=ans[i-];
}
} inline bool scan_d(int &num)
{
char in;bool IsN=false;
in=getchar();
if(in==EOF) return false;
while(in!='-'&&(in<''||in>'')) in=getchar();
if(in=='-'){ IsN=true;num=;}
else num=in-'';
while(in=getchar(),in>=''&&in<=''){
num*=,num+=in-'';
}
if(IsN) num=-num;
return true;
} void print_f(int x){
if(x==)return;
print_f(x/);
putchar(x%+'');
}
int main()
{
//freopen("data.txt","r",stdin);
int t ;
dedeal();
deal();
scan_d(t) ;
while(t--)
{
int n ;
scan_d(n) ;
if(n==)
putchar('') ;
else
print_f(ans[n]) ;
putchar('\n') ;
}
return ;
}
2973
HDU - 2973 - YAPTCHA的更多相关文章
- HDU 2973 YAPTCHA (威尔逊定理)
YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu 2973"YAPTCHA"(威尔逊定理)
传送门 题意: 给出自然数 n,计算出 Sn 的值,其中 [ x ]表示不大于 x 的最大整数. 题解: 根据威尔逊定理,如果 p 为素数,那么 (p-1)! ≡ -1(mod p),即 (p-1)! ...
- HDU - 2973:YAPTCHA (威尔逊定理)
The math department has been having problems lately. Due to immense amount of unsolicited automated ...
- hdoj 2111 Saving HDU
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- javase - 点餐系统
public class OrderMsg { public static void main(String[] args) throws Exception { /** * 订餐人姓名.选择菜品.送 ...
- maven工程读取resource下配置文件
maven工程读取resource下配置文件 在maven工程中,我们会将配置文件放到,src/main/resources 下面,例如 我们需要确认resource 下的文件 编译之后存放的位置 ...
- 【撸码caffe四】 solver.cpp&&sgd_solver.cpp
caffe中solver的作用就是交替低啊用前向(forward)算法和后向(backward)算法来更新参数,从而最小化loss,实际上就是一种迭代的优化算法. solver.cpp中的Solver ...
- 第7章 Android中访问网络资源
http://developer.android.com/index.html->https://developer.android.com/index.html https://develop ...
- Check the difficulty of problems(概率+DP)
http://poj.org/problem?id=2151 看的题解..表示没看懂状态转移方程.. #include<stdio.h> #include<string.h> ...
- mac下idea卡顿问题解决
idea在加载相对来说比较大的系统时,经常性出现卡顿,就是直接卡死,以至于写起代码特别难受. 最后找到的解决方案是修改idea.vmoptions中的内存大小 执行 find / -name idea ...
- css中background-clip属性的作用
background-clip属性的通俗作用就是指定元素背景所在的区域,有四种取值 1.border-box border-box是默认值,表示元素的背景从border区域(包括border)以内开始 ...
- Leetcode0100--Same Tree 相同树
[转载请注明]http://www.cnblogs.com/igoslly/p/8707664.html 来看一下题目: Given two binary trees, write a functio ...
- node 连接MySQL及其分装, 连接池连接
const mysql = require('mysql') const config = require('./../../config/config.default') var connectio ...
- Deutsch lernen (03)
1. das Gewerbe, - 行业 Was ist Ihr Gewerbe? Welches Gewerbe treibt er? treiben - trieb - getrieben 从事 ...