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. 07 MySQL安装图解--Windows版本

    MySQL安装图解 使用微信扫码关注微信公众号,并回复:"MySQL环境",免费获取下载链接! 1.安装MySQL 2.校验MySQL 3.登录MySQL 登录MySQL:mysq ...

  2. Docker环境中部署Prometheus及node-exporter监控主机资源

    前提条件 已部署docker 已部署grafana 需要开放 3000 9100 和 9090 端口 启动node-exporter docker run --name node-exporter - ...

  3. Centos7服务器上RabbitMQ单机安装

    一.背景 最近项目中用到了RabbitMQ,但是发现自己本地没有安装,此文记录一下本地RabbitMQ的安装过程.注意不同的系统安装方式略有不同,此处我们记录的是Centos7的安装方式. 二.安装方 ...

  4. HTML 基本标签2

    HTML标题通过<h1>-<h6>标签定义(<h1>定义最大的标题,<h6>定义最小的标题) <html>用于定义HTML文档 HTML段落 ...

  5. day07 MySQL索引事务

    day07 MySQL索引事务 昨日内容回顾 pymysql模块 # 链接数据库都是使用这个模块的 # 创建链接 import pymysql conn = pymysql.connect( host ...

  6. STM32代码常见的坑

    1 混淆换行符\和除号/造成的坑 入坑代码: GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin ...

  7. Linux学习 - 环境变量配置文件

    一.环境变量配置文件的作用 /etc/profile /etc/profile.d/*.sh ~/.bash_profile ~/.bashrc /etc/bashrc 1 /etc/profile的 ...

  8. Android Loader异步装载

    一.Loader简介: (一).Loader的概念: 装载器从android3.0开始引进.它使得在activity或fragment中异步加载数据变得简单. 当成批显示数据的时候,为了使用户体验更好 ...

  9. docker之镜像制作

    #:下载镜像并初始化系统 root@ubuntu:~# docker pull centos #:创建目录 root@ubuntu:/opt# mkdir dockerfile/{web/{nginx ...

  10. JavaBean的命名规则

    JavaBean的命名规则Sun 推荐的命名规范1 ,类名要首字母大写,后面的单词首字母大写2 ,方法名的第一个单词小写,后面的单词首字母大写3 ,变量名的第一个单词小写,后面的单词首字母大写为了使 ...