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的更多相关文章
随机推荐
- 【计算机网络】一步一步学习IP路由流程
TCP/IP协议簇是目前互联网应用最广的协议栈,谈到TCP/IP协议栈就不能不讲一讲IP路由的问题,因为在我们使用的网络通信中几乎每时每刻都在发生着IP路由的事件…….当你在网络世界中还是一位新手的时 ...
- IIS下发布关于Excel导入导出时遇到的问题集锦(转)
问题描述 1.Excel每个工作薄(sheet)生成记录行数 2.asp.net关于导出Excel的一些问题的集锦 3.下载失败,临时文件或其所在磁盘不可写 4.未能加载文件或程序集“Microsof ...
- Access 2010入门、语文
Access2010入门 数据管理库是按照数据结构来组织,存储和管理数据的仓库. 最早出现的数据库是网状DBMS 1970年,EFCodd博士提出关系模型的概念,提出关系模型的理论基础. SQL语言功 ...
- Python模块入门(一)
一.模块介绍 模块就是一系列功能的集合体 模块有三种来源: 1.内置模块:python内提供的模块 2.第三方模块:由第三方提供的模块 3.自定义模块:自行定义的模块 模块的格式: 1.使用pytho ...
- (WPF) DataGrid之绑定
通过ObservableCollection 绑定到 DataGrid. 1. 前台Xaml. <DataGrid x:Name="dgMeasurements" Horiz ...
- php 编译安装指导
php 编译安装 下载源码 安装 安装后配置 下载源码 php下载地址:http://php.net/downloads.php php-7.1.11.tar.bz2 安装 安装依赖包 yum ins ...
- 使用坚果云+keepass实现网盘密码管理
准备工作 登录坚果云web版 在主页创建了一个新的同步文件夹AAA(与同步文件夹My Nutstore并列) 设置同步文件夹AAA:勾选“默认不同步到电脑” 把KeePass的数据库文件db.kdbx ...
- java设置随机数教程
java作为程序猿开发人员都在使用的一款编程语言,许多入门的朋友都陷入了一个简单的问题就是,使用java开发时随机数要怎么设置?java怎么设置随机数?经常会有地方需要用到随机数,不用着急,一起来看看 ...
- U深度U盘启动盘制作工具怎么用?U深度U盘启动盘制作工具使用教学
U深度u盘启动盘制作工具是一款强大的启动盘制作软件,对于新手用户来说,由于软件专业度很高,想一下就上手是比较困难的.所以这里给大家分享一篇U深度u盘启动盘制作工具的使用教程. 使用教程: 第一步:安装 ...
- git(github)常用命令
安装git sudo apt-get install git 显示git版本 git version 显示system属性,对应为/etc/gitconfig文件的内容 git config --sy ...