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 ;
}

最新文章

  1. Node.js在Chrome进行调试
  2. js 除法 取整
  3. html之小积累-.-iframe自适应高度
  4. EasyUI DataGrid 添加排序
  5. MySQL定期分析检查与优化表
  6. spring BeanFactory概述
  7. Extjs3 Combo实现百度搜索查询
  8. JavaScript---网络编程(11)--DHTML技术演示(4)-单选框/下拉菜单/添加文件
  9. shell获取日期(昨天,明天,上月,下月)
  10. 需要熟悉的几个调试命令:objdump/pmap/ldd/stace
  11. Problem 2128 最长子串(kmp+strstr好题经典)
  12. ucGUI的学习小结
  13. DevOps概述
  14. go os/exec执行外部程序
  15. (1)Java数据结构--图文并茂-分析优缺点
  16. 洛谷 P2467 地精部落 解题报告
  17. Element ui tree结合Vue使用遇到的一些问题(一)
  18. [python] 列表解析式的高效与简洁
  19. 新网站如何做SEO优化【转】
  20. unity-------------UI的界面调节

热门文章

  1. intellij 引入本地库并war打包
  2. 【dpdk】使用libpcap-PMD驱动收发包
  3. Sublime Text3 实现在浏览器中以HTML格式预览md文件
  4. POJ 2603
  5. redis安装(linux)
  6. div居中的几种方式
  7. 理解WSGI
  8. js 开发过程中经验及总结记录
  9. 二:理解ASP.NET的运行机制(例:基于HttpHandler的URL重写)
  10. PHP之高性能I/O框架:Libevent(一)