UVA_1434_YAPTCHA
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的更多相关文章
随机推荐
- 模拟登陆并爬取Github
因为崔前辈给出的代码运行有误,略作修改和简化了. 书上例题,不做介绍. import requests from lxml import etree class Login(object): def ...
- C++(SOCKET)简单爬虫制作
先给出代码:(我使用的是VS编译器,需要在项目->project属性-> #include <iostream> #include <stdio.h> #inclu ...
- MATLAB基本概念和变量
基本概念 1.x=int8(129)=>x=127 (带符号8位整数,最大值为127) x=uint8(129)=>x=129 (无符号型,最大值为255) 2.class函数得 ...
- hduoj 2955Robberies
Robberies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- Visual Studio 2017 安装失败,你们有这样的问题吗?怎么解决
由于发生一个或多个包故障,产品未能安装列出的工作负荷和组件. 工作负荷不完整 使用 JavaScript 的移动开发 (Microsoft.VisualStudio.Workload.WebCross ...
- VMWare 9 安装 win8
http://tieba.baidu.com/p/1954912175 http://down.51cto.com/data/497803 win8专业版:NBCCB-JJJDX-PKBKJ-KQX8 ...
- webConfig中<customErrors>节点配置
发布在远程计算机上的网站调试问题: 通常情况下我们会设置错误页,不让用户看到错误信息 这种WebConfig的配置方法是: <configuration> <system.web&g ...
- DO、PO、BO、DTO、VO等概念
PO 全称为:Persistant Object,持久化对象,与数据库结构映射的实体,数据库中的一条数据即为一个 PO 对象. BO 全称为:Business Object,业务对象,主要作用是把业务 ...
- C++ Knowledge series Template & Class
Function Function is composed of name, parameter (operand, type of operand), return value, body with ...
- Java—封装
封装 将类的某些信息隐藏在类的内部,不允许外部程序直接访问,而是通过该类提供的方法类实现对隐藏信息的操作和访问. 封装的实现步骤:修改属性的可见性(设为private)=>创建setter和ge ...