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.

InputThe first line contains the number of queries t (t <= 10^6). Each query consist of one natural number n (1 <= n <= 10^6).OutputFor 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 被减数P 一定大于减数Q,并且P,Q相差不大,转化成了当切仅当P为整数的时候。
威尔逊定理:当且仅当p为素数时:( p -1 )! ≡ -1 ( mod p )
通过威尔逊定理,(P-1)!+1≡ 0 ( mod p ),本题就转化成求3*k+7是否为素数的问题。
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define mod 1000000
#define N 3000005
typedef long long LL;
int prime[N];
bool vis[N];
int val[N];
int pn=0;
int ans[N];
int main ()
{
for (int i = 2; i < N; i++) {
if (vis[i]) continue;
val[i]=1;
prime[pn++] = i;
for (int j = i; j < N; j += i)
vis[j] = 1;
}
for(int i=1;i<=1000000;i++)
{
ans[i+1]=ans[i]+val[3*i+10];
}
int t;
while(~scanf("%d",&t))
{
int n;
while(t--)
{
scanf("%d",&n);
cout<<ans[n]<<endl;
}
} }

  

UVA_1434_YAPTCHA的更多相关文章

随机推荐

  1. (转)轻松应对IDC机房带宽突然暴涨问题

    原文:http://blog.51cto.com/oldboy/909696

  2. springboot 整合redisson

    整合代码已经过测试 1.pom <!-- redisson --> <dependency> <groupId>org.redisson</groupId&g ...

  3. 洛谷P3128 [USACO15DEC]最大流Max Flow(树上差分)

    题意 题目链接 Sol 树上差分模板题 发现自己傻傻的分不清边差分和点差分 边差分就是对边进行操作,我们在\(u, v\)除加上\(val\),同时在\(lca\)处减去\(2 * val\) 点差分 ...

  4. Thymeleaf基础知识

    Thymeleaf是一个Java类库,它是一个xml/xhtml/html5的模板引擎,可以作为MVC的Web引用的View层. Thymeleaf还提供了额外的模块与SpringMVC集成,因此推荐 ...

  5. SharePoint 栏的三种名字Filed :StaticName、 InternalName、 DisplayName

    SharePoint 的栏,有3个名字, StaticName InternalName  DisplayName. 当在第一次创建栏的时候,这3个名字一起进行创建,并且都一样. <FIELD  ...

  6. 数组模拟栈(C语言)

    用数组模拟栈的实现: #include <stdio.h> #include <stdlib.h> #define STACK_SIZE 100 typedef struct ...

  7. [原创][Windows] Win7安装visual c++ 2015 redistributable x64失败

    在win7中安装visual c++ 2015 redistributable x64 时会卡住,原因是visual c++ 2015 redistributable x64 需要KB2999226, ...

  8. STM32开发-MDK新建工程及配置

    本人也是接触stm32没多久,之前用的MDK是5.1,现在用的是5.13,MDK5.0之前的版本(本人简称旧版)和之后的版本(本人简称新版)新建工程有很大区别.对于刚开始用学stm32的新手来说,基本 ...

  9. cs231n 17-18 assignment2 出现 No module named 'past' 解决方法

    解决方法: pip install future

  10. Java UUID Generator(JUG)

    UG 是一个纯 Java 的 UUID 生成器. UUID是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的.通常平台会提供生成UUID的API.UUID按照开放软件基金 会 (OS ...