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

  1. 4
  2. 2
  3. 4
  4. 5
  5. 231

Sample Output

  1. 1 2 5
  2. 2 4 13
  3. 3 5 21
  4. 4 231 32549
  5.  
  6. 思路:裸的欧拉函数,相当于求在第一象限有多少个不同斜率的点,k=y/x,当yx互质时,其值唯一,直接打表求欧拉函数前缀和就行,y,x不同所以要乘2y,x相同时未算,所以要加1
  1. const int maxm = ;
  2.  
  3. int Euler[maxm];
  4.  
  5. void get_Euler() {
  6. Euler[] = ;
  7. for(int i = ; i <= maxm; ++i) {
  8. if(!Euler[i]) {
  9. for(int j = i; j <= maxm; j += i) {
  10. if(!Euler[j]) Euler[j] = j;
  11. Euler[j] = Euler[j] / i * (i-);
  12. }
  13. }
  14. }
  15. }
  16.  
  17. int main() {
  18. get_Euler();
  19. for(int i = ; i <= maxm; ++i)
  20. Euler[i] += Euler[i-];
  21. int T, N;
  22. scanf("%d", &T);
  23. for(int i = ; i <= T; ++i) {
  24. scanf("%d", &N);
  25. printf("%d %d %d\n", i, N, * Euler[N] + );
  26. }
  27. return ;
  28. }
  1.  

Day7 - A - Visible Lattice Points POJ - 3090的更多相关文章

  1. 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5636   Accepted: ...

  2. 【POJ】3090 Visible Lattice Points(欧拉函数)

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7705   Accepted: ...

  3. poj 3060 Visible Lattice Points

    http://poj.org/problem?id=3090 Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Tota ...

  4. spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演

    SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...

  5. Spoj 7001 Visible Lattice Points 莫比乌斯,分块

    题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193   Visible Lattice Points Time L ...

  6. P8 Visible Lattice Points

    P8 Visible Lattice Points Time Limit:1000ms,     Memory Limit:65536KB Description A lattice point (x ...

  7. POJ3090 Visible Lattice Points

    /* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...

  8. Visible Lattice Points (莫比乌斯反演)

    Visible Lattice Points 题意 : 从(0,0,0)出发在(N,N,N)范围内有多少条不从重合的直线:我们只要求gcd(x,y,z) = 1; 的点有多少个就可以了: 比如 : 点 ...

  9. SPOJ1007 VLATTICE - Visible Lattice Points

    VLATTICE - Visible Lattice Points no tags  Consider a N*N*N lattice. One corner is at (0,0,0) and th ...

随机推荐

  1. HTML中的ul标签

    UL格式: <ul> <li>Coffee</li> <li>Tea</li> <li>Milk</li> < ...

  2. 关于and 和or的执行优先级问题分析

    题目:列出本店价低于60或者高于100.并且商品点击数大于628的商品. 按照下面两种写法,得到的结果是不同的. 第一种:结果数据中有点击数为628的记录,显然不符合题目要求. SELECTgoods ...

  3. c# 字符串比较优化

    一,优化举例 二,浅谈StringComparison 三,C# CultureInfo 类 各国语言对应的区域性名称 一,优化举例 我们在写程序的时候,经常会用到字符串对比.例如:if(IsChec ...

  4. java记录1--接口

    接口(interface)定义:抽象方法和常量值的集合.本质上讲,接口是一种特殊的抽象类 ps:1.接口中定义的属性必须是public static final 的,定义的方法必须是public ab ...

  5. java垃圾回收学习

    经过一个晚上的努力终于完成了一个文件替换指定字符串的程序,但是由于我要替换的全站程序html文件太多, 所以eclipse下边老是在一个目录结束后报出java.lang.OutOfMemoryErro ...

  6. CMake构建Qt5的VS2015项目 (Hello Qt5)

    Qt5的编译 Windows下载编译Qt5 Gui CMakeLists.txt 源码 cmake_minimum_required(VERSION 2.8.11) project(HelloQt5) ...

  7. Ngnix简介

    Nginx的产生 没有听过Nginx?那么一定听过它的"同行"Apache吧!Nginx同Apache一样都是一种WEB服务器.基于REST架构风格,以统一资源描述符(Unifor ...

  8. IDEA导入项目后,导入artifacts 方法 以及 Spring的配置文件找不到的解决方法

    我们一般选择 open 项目,如果没有artifacts 的添加选项,我们就要选择 import 项目. 如果没有artifacts ,项目下面会有错误提示,点击错误提示Fix,设置里面导入artif ...

  9. java 调用阿里云短信接口,报InvalidTimeStamp.Expired : Specified time stamp or date value is expired.

    官网解释: 问题所在: 自己的电脑(或者服务器) 的时间与阿里云的服务器时间 相差15分钟了. 解决方法 : 把自己的电脑时间 (或者服务器)的时间 改成标准的北京时间就行了.

  10. Java程序生成exe可执行文件

    Java程序打包成exe可执行文件,分为两大步骤. 第一步:将Java程序通过Eclipse或者Myeclipse导成Jar包 第二步:通过exe4j讲Jar包程序生成exe可执行文件 第一步详解: ...