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的更多相关文章
随机推荐
- 【LDAP】Openldap导入数据
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://jerry12356.blog.51cto.com/4308715/1851186 ...
- 【计算机网络】一步一步学习IP路由流程
TCP/IP协议簇是目前互联网应用最广的协议栈,谈到TCP/IP协议栈就不能不讲一讲IP路由的问题,因为在我们使用的网络通信中几乎每时每刻都在发生着IP路由的事件…….当你在网络世界中还是一位新手的时 ...
- 用Windows Live Writer离线写博客
作为CSDN博客的菜鸟,我发现在线写博客很不方便,而且文字编辑也不方便,比如不能傻瓜化地修改字体和颜色."有志者自有千方百计,无志者只感千难万难."一番搜索后,我发现了Window ...
- php 入门
<?php $username = $_POST["username"]; $passcode = $_POST["passcode"]; # 一定要my ...
- 解决navicate 连接mysql数据库中文乱码的问题
以下均是ubuntu12.04为准 1.修改mysql的配置文件. 1.1.vi /etc/mysql/my.conf找到[client]在其下面添加 default-character-set=u ...
- sqlmap注入技巧
收集了一些利用Sqlmap做注入测试的TIPS,其中也包含一点绕WAF的技巧,便于大家集中查阅,欢迎接楼补充.分享. TIP1 当我们注射的时候,判断注入 http://site/script?id= ...
- 一步步理解typedef
1.如何用C语言实现一个函数,传递两个整形数,返回两个数的和? #include<stdio.h> int add(int a,int b) { return a+b; } void ma ...
- Thinkphp 出现 “_CACHE_WRITE_ERROR” 错误的可能解决办法
有可能是老毛病: Cache文件夹和里面的文件,php没有权限 解决办法: chmod -R 777 /.............../www/Cache
- ScrollView监听滑动到顶部和底部的方法
不需要监听滑动位置,只需要重写ScrollView的onOverScrolled和stopNestedScroll方法就可以了 public class ReadScrollView extends ...
- [SVN]TortoiseSVN工具培训2─SVN的基本概念和工作模式
1.SVN是什么? TortoiseSVN,属于集中式版本控制工具,是Subversion版本控制系统的一个免费SVN开源客户端,可以对文件版本进行统一管理和控制:文件保存在中央版本库,您可以将文件恢 ...