YAPTCHA

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 862    Accepted Submission(s): 452

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
思路:素数打表+威尔逊定理;
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<queue>
6 #include<set>
7 #include<math.h>
8 using namespace std;
9 typedef long long LL;
10 bool prime[4000000];
11 int sum[4000009];
12 int main(void)
13 {
14 int n;
15 memset(prime,0,sizeof(prime));
16 for(int i = 2; i < 3000; i++)
17 {
18 if(!prime[i])
19 for(int j = i; (i*j) <=4000007 ; j++)
20 {
21 prime[i*j] = true;
22 }
23 }
24 memset(sum,0,sizeof(sum));
25 for(int i = 1; i <= 1000000; i++)
26 {
27 if(!prime[3*i+7])
28 sum[i] = sum[i-1] + 1;
29 else sum[i] = sum[i-1];
30 }
31 scanf("%d",&n);
32 while(n--)
33 {
34 int ask ;
35 scanf("%d",&ask);
36 printf("%d\n",sum[ask]);
37 }
38 return 0;
39 }

YAPTCHA(hdu2973)的更多相关文章

  1. YAPTCHA(HDU2973)【威尔逊定理】

    威尔逊原理.即对于素数p,有(p-1)!=-1( mod p). 首先,将原式变形为[ (3×k+6)! % (3×k+7) + 1] / (3×k+7),所以: 1.3×k+7是素数,结果为1, 2 ...

  2. hdu2973 YAPTCHA【威尔逊定理】

    <题目链接> 题目大意: The task that is presented to anyone visiting the start page of the math departme ...

  3. uva 1434 - YAPTCHA(数论)

    题目链接:uva 1434 - YAPTCHA 题目大意:给定n和k,求题目中给定的式子S(n). 解题思路:威尔逊定理,x为素数时有,((x−1)!+1)%x==0,所以对于本题.假设3*k+7为素 ...

  4. HDU2973(威尔逊定理)

    YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  5. 威尔逊定理--HDU2973

    参考博客 HDU-2973 题目 Problem Description The math department has been having problems lately. Due to imm ...

  6. HDU - 2973 - YAPTCHA

    先上题目: YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  7. HDU 2973 YAPTCHA (威尔逊定理)

    YAPTCHA Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  8. HDU2937 YAPTCHA(威尔逊定理)

    YAPTCHA Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  9. hdu 2973"YAPTCHA"(威尔逊定理)

    传送门 题意: 给出自然数 n,计算出 Sn 的值,其中 [ x ]表示不大于 x 的最大整数. 题解: 根据威尔逊定理,如果 p 为素数,那么 (p-1)! ≡ -1(mod p),即 (p-1)! ...

随机推荐

  1. 11-String to Integer (atoi)

    字符串转整型,更新之后的leetcode题,需考虑各种情况, 测试过标准库的atoi函数,当字符串越界返回的值是错的, 而该题要求越界时的返回边界值,更加严谨. Implement atoi to c ...

  2. A Child's History of England.28

    By such means, and by taxing and oppressing the English people in every possible way, the Red King b ...

  3. Struts 2 基础篇【转】

    转载至 : http://www.blogjava.net/huamengxing/archive/2009/10/21/299153.html Struts2架构图 有视频讲解百度一下就可以找到了 ...

  4. Linux的小知识

    1. top 命令可以在Linux下查看任务管理器和当前进程使用资源情况. 2. Ctrl+c 即可退出,然后使用 kill+进程号 命令可杀死指定进程 3.在Linux的 /etc/rc.local ...

  5. 【STM32】使用SDIO进行SD卡读写,包含文件管理FatFs(七)-准备移植FatFs

    [STM32]使用SDIO进行SD卡读写,包含文件管理FatFs(一)-初步认识SD卡 [STM32]使用SDIO进行SD卡读写,包含文件管理FatFs(二)-了解SD总线,命令的相关介绍 [STM3 ...

  6. oracle异常处理——ORA-01000:超出打开游标最大数

    oracle异常处理--ORA-01000:超出打开游标最大数https://www.cnblogs.com/zhaosj/p/4309352.htmlhttps://blog.csdn.net/u0 ...

  7. mysql死锁com.mysql.cj.jdbc.exception.MYSQLTransactionRollbackException Deadlock found when trying to get lock;try restarting transaction

    1.生产环境出现以下报错 该错误发生在update操作中,该表并未建立索引,也就是只有InnoDB默认的主键索引,发生错误的程序是for循环中update. 什么情况下会出现Deadlock foun ...

  8. Linux 双网卡绑定及Bridge

    Linux 双网卡绑定及Bridge 阅读(5,202) 一:linux操作系统下双网卡绑定有七种模式.现在一般的企业都会使用双网卡接入,这样既能添加网络带宽,同时又能做相应的冗余,可以说是好处多多. ...

  9. 一文读懂RESTful架构

    转载自https://zhuanlan.zhihu.com/p/381554129 RESTful架构究竟是什么 别着急,想要了解RESTful,我们先来了解一位大佬Roy Thomas Fieldi ...

  10. Ajax异步更新网页(使用原生JavaScript)

    一.页面代码 <!DOCTYPE html> <html> <head> <title>MyHtml.html</title> <me ...