欧拉函数裸题,直接欧拉函数值乘二加一就行了。具体证明略,反正很简单。

题干:

Description

A lattice point (x, y) 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 (x, y) 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 (x, y) with 0 ≤ x, y ≤ 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 (x, y) with 0 ≤ x, yN.

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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
int phi[],n;
void init(int n)
{
phi[] = ;
duke(i,,n)
{
phi[i] = i;
}
duke(i,,n)
{
if(phi[i] == i)
{
for(int j = i;j <= n;j += i)
{
phi[j] = phi[j] / i * (i - );
}
}
}
duke(i,,n)
{
phi[i] = phi[i - ] + phi[i];
}
}
int dp[],maxn = ;
int main()
{
read(n);
duke(i,,n)
{
read(dp[i]);
maxn = max(maxn,dp[i]);
}
init(maxn);
duke(i,,n)
{
printf("%d %d %d\n",i,dp[i],phi[dp[i]] * + );
}
return ;
}
代码:

最新文章

  1. 设计上如何避免EMC问题
  2. JS实现文字截取(雾)
  3. SQL 存储过程 传入数组参数
  4. Swift---- 可选值类型(Optionals) 、 断言(Assertion) 、 集合 、 函数
  5. CoffeeRobotTeam项目组报告
  6. 如何让ASP.NET网站站点不停止 永远持续运行
  7. SQL Server: Difference Between Locking, Blocking and Dead Locking
  8. linux之ioctl函数解析
  9. JAVA基础--异常
  10. ES6常用语法整合
  11. 浅谈如何用Java操作MongoDB
  12. UGUI 粒子特效与UI层级问题
  13. 51NOD 1185 威佐夫游戏 V2(威佐夫博弈)
  14. 软件工程 #02# Entity Relationship Diagram VS. 用 UML 中的类图表示 E-R 图
  15. C#列的一些操作
  16. BZOJ 1093 [ZJOI2007]最大半连通子图 - Tarjan 缩点
  17. Caffe 深度学习框架上手教程
  18. HotSpot VM
  19. drupal7整合Discuz康盛UC用户中心ucenter,ucuser模块
  20. 高性能CSS

热门文章

  1. datagrid总条数
  2. oracle中的冷热备份
  3. 本地搭建easy-mock
  4. airfoil polar data during post stall stages (high AOA)
  5. 洛谷 1091 合唱队形(NOIp2004提高组)
  6. Python基础(十一) 异常处理
  7. 聊聊餐饮: 2016年,是我做生意9年来,最差的1年 by某老板
  8. 自己写一个HashMap
  9. App后台开发运维和架构实践学习总结(3)——RestFul架构下API接口设计注意点
  10. mySQL and sqoop for ubuntu