Description

问从点(0,0)能看到点(0,0)和(n,n)之间的矩形的多少个整数点,看到(x,y)代表点(0,0)和点(x,y)间没有其他整数点,如看不到(2,4)因为中间有点(1,2)

Input

一行一个正整数n

Output

一行一个数表示能看到多少个点

Sample Input

2

Sample Output

5

HINT

样例解释:能看到(0,1)(1,0)(1,1)(2,1)(1,2)5个点

数据范围:

对于20%的数据n<=1000

对于50%的数据n<=100000

对于100%的数据n<=10000000


非常典型的欧拉函数的应用.

不说话, 直接上代码(欧拉函数这种东西要背熟啊)

#include<iostream>
#include<string.h>
using namespace std;
/*
void phi_table()
{
memset(phi,0,sizeof(phi));
phi[1] = 1;
for(int i = 2; i <= N; i++)
if(!phi[i])
for(int j = i; j <= N; j += i)
{
if(!phi[j])
phi[j] = j;
phi[j] = phi[j] / i * (i - 1);
}
}
*/
const int maxN = (int)1e7;
int phi[maxN + 1];
int main()
{
#ifndef ONLINE_JUDGE
freopen("see.in", "r", stdin);
freopen("see.out", "w", stdout);
#endif
int n;
cin >> n;
memset(phi, 0, sizeof(phi));
phi[1] = 1;
for(int i = 2; i <= n; i ++)
if(! phi[i])
for(int j = i; j <= n; j += i)
{
if(! phi[j])
phi[j] = j;
phi[j] = phi[j] / i * (i - 1);
}
long long ans = 0;
for(int i = 1; i <= n; i ++)
ans += phi[i];
cout << ans * 2 + 1;
}

随机推荐

  1. __block 和__weak

    1,在MRC 时代,__block 修饰,可以避免循环引用:ARC时代,__block 修饰,同样会引起循环引用问题: 2,__block不管是ARC还是MRC模式下都可以使用,可以修饰对象,还可以修 ...

  2. LRESULT CALLBACK WndProc 窗口程序的 重点

    LRESULT CALLBACK WndProc Windows程序所作的一切,都是回应发送给窗口消息处理程序的消息.这是概念上的主要难点之一,在开始写作Windows程序之前,必须先搞清楚. 窗口消 ...

  3. day03_06 变量详解

    print ("hello world") print("alex") print("jinxing") print("3乘以4= ...

  4. 用Python表达对Android的想法

    组员:喻航,张子东 视频:点我 #DISCARD ANDROID TODAY! import turtle import turtle as gui #setting turtle.screensiz ...

  5. 为Anaconda添加新的源

    为Anaconda添加新的源 在cmd中输入以下内容即可, 清华的源,速度非常快 conda config --add channels https://mirrors.tuna.tsinghua.e ...

  6. Sogou日志分析(hive)

    1. 数据准备 1.1 数据预先放在mac本地桌面的“VB共享文件夹”中,从VisualBox虚拟机中/mnt/VBShare共享目录中转移到resources目标目录. [cloudera@quic ...

  7. AtCoder Regular Contest 080

    手贱去开了abc,这么无聊.直接arc啊 C - 4-adjacent Time limit : 2sec / Memory limit : 256MB Score : 400 points Prob ...

  8. mysql使用日常备忘

    批量插入数据时,如果主键是有业务意义的,并非自自增张,那么有可能在插入的数据中有与已存在的键值重复的,可以用如下方式来插入: INSERT IGNORE 当要插入一个数据时,插入的字段值中主键字段或唯 ...

  9. poj1985&&第四次CCF软件认证第4题 求树的直径

    Cow Marathon Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 4216   Accepted: 2137 Case ...

  10. 测试jsonp

    login<?php $type = $_GET['type']; if(empty($type)) { $url = ""; }else { if($type == 'lo ...