Visible Lattice Points

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7450   Accepted: 4536

Description

A lattice point (xy) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (xy) does not pass through any other lattice point. For example, the point (4, 2) is not visible since the line from the origin passes through (2, 1). The figure below shows the points (xy) with 0 ≤ xy ≤ 5 with lines from the origin to the visible points.

Write a program which, given a value for the size, N, computes the number of visible points (xy) with 0 ≤ xy ≤ N.

Input

The first line of input contains a single integer C (1 ≤ C ≤ 1000) which is the number of datasets that follow.

Each dataset consists of a single line of input containing a single integer N (1 ≤ N ≤ 1000), which is the size.

Output

For each dataset, there is to be one line of output consisting of: the dataset number starting at 1, a single space, the size, a single space and the number of visible points for that size.

Sample Input

4
2
4
5
231

Sample Output

1 2 5
2 4 13
3 5 21
4 231 32549

Source

 //2017-08-04
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
int phi[N],prime[N],tot,ans;
bool book[N]; void getphi()
{
int i,j;
phi[]=;
for(i=;i<=N;i++)//相当于分解质因式的逆过程
{
if(!book[i])
{
prime[++tot]=i;//筛素数的时候首先会判断i是否是素数。
phi[i]=i-;//当 i 是素数时 phi[i]=i-1
}
for(j=;j<=tot;j++)
{
if(i*prime[j]>N) break;
book[i*prime[j]]=;//确定i*prime[j]不是素数
if(i%prime[j]==)//接着我们会看prime[j]是否是i的约数
{
phi[i*prime[j]]=phi[i]*prime[j];break;
}
else phi[i*prime[j]]=phi[i]*(prime[j]-);//其实这里prime[j]-1就是phi[prime[j]],利用了欧拉函数的积性
}
}
} int solve(int n){
int ans = ;
for(int i = ; i <= n; i++){
ans += phi[i];
}
return ans*+;
} int main()
{
int T, n, kase = ;
getphi();
scanf("%d", &T);
while(T--){
scanf("%d", &n);
cout<<++kase<<" "<<n<<" "<<solve(n)<<endl;
} return ;
}

POJ3090(SummerTrainingDay04-M 欧拉函数)的更多相关文章

  1. POJ3090 巧用欧拉函数 phi(x)

    POJ3090 给定一个坐标系范围 求不同的整数方向个数 分析: 除了三个特殊方向(y轴方向 x轴方向 (1,1)方向)其他方向的最小向量表示(x,y)必然互质 所以对欧拉函数前N项求和 乘2(关于( ...

  2. poj3090欧拉函数求和

    E - (例题)欧拉函数求和 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     ...

  3. 欧拉函数,打表求欧拉函数poj3090

    欧拉函数 φ(n) 定义:[1,N]中与N互质的数的个数 //互质与欧拉函数 /* 求欧拉函数 按欧拉函数计算公式,只要分解质因数即可 */ int phi(int n){ int ans=n; ;i ...

  4. 算法复习——欧拉函数(poj3090)

    题目: Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or e ...

  5. POJ3090 Visible Lattice Points 欧拉函数

    欧拉函数裸题,直接欧拉函数值乘二加一就行了.具体证明略,反正很简单. 题干: Description A lattice point (x, y) in the first quadrant (x a ...

  6. hdu2588 GCD (欧拉函数)

    GCD 题意:输入N,M(2<=N<=1000000000, 1<=M<=N), 设1<=X<=N,求使gcd(X,N)>=M的X的个数.  (文末有题) 知 ...

  7. BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][ ...

  8. BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】

    2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 4436  Solved: 1957[Submit][Status][Discuss ...

  9. COGS2531. [HZOI 2016]函数的美 打表+欧拉函数

    题目:http://cogs.pw/cogs/problem/problem.php?pid=2533 这道题考察打表观察规律. 发现对f的定义实际是递归式的 f(n,k) = f(0,f(n-1,k ...

随机推荐

  1. c setjmp longjmp

    http://coolshell.cn/?s=setjmp http://www.cnblogs.com/hazir/p/c_setjmp_longjmp.html double divide(dou ...

  2. 解决ssh远程连接错误问题

    使用 Xshell 远程连接服务器时,经常会出现这么个错误提示 WARNING! The remote SSH server rejected X11 forwarding request. ➜ ~ ...

  3. linux安装mysql数据库和简单配置

  4. 没啥事用C语言写一个Trie tree玩玩,支持中英文,用g++编译通过

    #include <cstdio> #include <cstdlib> #include <vector> #define ALPHABETS 2600000 # ...

  5. MySQL查询表结构命令

    参考网址:https://www.cnblogs.com/zhangyuhang3/p/6873895.html 一.简单描述表结构,字段类型 desc tabl_name; desc tabl_na ...

  6. hao643.com劫持(修改快捷方式跳转至hao123.com)

    >症状:所有浏览器快捷方式,都被加上尾巴,例如IE的:"C:\Program Files\Internet Explorer\iexplore.exe" http://hao ...

  7. 工具-CocoaPods安装和使用及卸载

    CocoaPods是iOS最常用的第三方类库管理工具,绝大部分有名的开源类库都支持CocoaPods. 我们在使用gem更新的时候,经常会为速度抓狂,其实gem默认的源是https://rubygem ...

  8. Vue笔记:使用 axios 发送请求

    在Vue1.0的时候有一个官方推荐的 ajax 插件 vue-resource,但是自从 Vue 更新到 2.0 之后,官方就不再更新 vue-resource. 关于为什么放弃推荐? -> 尤 ...

  9. 玩转mongodb(八):分布式计算--MapReduce

    MongoDB提供了MapReduce的聚合工具来实现任意复杂的逻辑,它非常强大,非常灵活.MapReduce使用JavaScript作为“查询语言”,能够在多台服务器之间并行执行.它会将一个大问题拆 ...

  10. 【IT笔试面试题整理】删除无序链表中重复的节点

    [试题描述]定义一个函数,输入一个链表,删除无序链表中重复的节点 [参考代码] 方法一: Without a buffer, we can iterate with two pointers: &qu ...