see
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;
}
随机推荐
- LeetCode(172)Factorial Trailing Zeroes
题目 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...
- gcc——预处理(预编译),编译,汇编,链接
一,预编译 操作步骤:gcc -E hello.c -o hello.i 主要作用: 处理关于 “#” 的指令 [1]删除#define,展开所有宏定义.例#define portnumber 333 ...
- excel日期格式取年份
具体思路:先将日期格式更改为常规格式,再取常规格式的前4位数字 例如:A1==1981/12/22 第一步B1=TEXT(A1,"emd") 第二步C1=LEFT(B1,4) 结束
- 《变革之心》读后感——《Scrum实战》第2次课作业
刚读了几篇序言.导言和第一个故事,因此读后感可能不全面,先写一下一点儿感受吧. <变革之心>讲的是组织变革,而组织变革是以个人变革为基础的,本书的观点就是在个人变革上,“目睹--感受--变 ...
- PYday16&17-设计模式\选课系统习题
1.设计模式:对程序做整体得规划设计,这样做是为了更好的实现功能,使代码的可扩展性更好有27种常见的设计模式.流行的设计模式参考书:GoF设计模式.大话设计模式设计模式是为了更好的实现模块间的解耦,便 ...
- canvas 动画库 CreateJs 之 EaselJS(上篇)
本文来自网易云社区 作者:田亚楠 须知 本文主要是根据 createjs 中的 EaselJS 在 github 上的 tutorials 目录下的文章整理而来 (原文链接),同时也包含了很多本人的理 ...
- windows系统使用的误区
1.软件不要装在c盘,影响系统运行速度. 软件c盘不会影响系统运行,会提高软件运行速度 PS:前提条件:C盘有足够的空余空间(50G以上). 大多数软件安装默认路径在C盘的原因是不知道电脑分区的情况, ...
- django html render_to_response
#coding=utf-8 from django.shortcuts import render from blog.models import BlogPost from django.short ...
- TOJ 4493 Remove Digits 贪心
4493: Remove Digits Description Given an N-digit number, you should remove K digits and make the new ...
- 错误处理: Python值传递和引用传递的问题
1.插入数据库的时候报错110, 提示columns数量少于插入的值内容. 2.核对了下栏目并没有少,打印出插入的值,看看值是不是多了. 查看了下,确实第二次值的时候长度边长了,第二次把第一次的部分值 ...