题目链接:传送门

思路:

  所有gcd(x, y) = 1的数对都满足题意,然后还有(1, 0) 和 (0, 1)。

#include <iostream>
#include <cstring> using namespace std;
const int MAX_N = 1e3 + ;
int prime[MAX_N+], phi[MAX_N+];
void getPrime_and_Phi() {
memset(prime, , sizeof prime);
phi[] = ;
for (int i = ; i <= MAX_N; i++) {
if (!prime[i]) prime[++prime[]] = i, phi[i] = i-;
for (int j = ; j <= prime[] && prime[j] <= MAX_N/i; j++) {
prime[i*prime[j]] = ;
phi[i*prime[j]] = phi[i] * (i%prime[j] ? prime[j]- : prime[j]);
if (i%prime[j] == ) break;
}
}
} int main()
{
getPrime_and_Phi();
int C;
cin >> C;
for (int kase = ; kase <= C; kase++) {
int N;
cin >> N;
long long ans = ;
for (int i = ; i <= N; i++)
ans += phi[i]*;
cout << kase << ' ' << N << ' ' << ans << endl;
}
return ;
}

POJ3090 Visible Lattice Points (数论:欧拉函数模板)的更多相关文章

  1. [POJ3090]Visible Lattice Points(欧拉函数)

    答案为3+2*∑φ(i),(i=2 to n) Code #include <cstdio> int T,n,A[1010]; void Init(){ for(int i=2;i< ...

  2. POJ_3090 Visible Lattice Points 【欧拉函数 + 递推】

    一.题目 A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), ...

  3. zoj 2777 Visible Lattice Points(欧拉函数,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<algo ...

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

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

  5. POJ 3090 Visible Lattice Points 【欧拉函数】

    <题目链接> 题目大意: 给出范围为(0, 0)到(n, n)的整点,你站在(0,0)处,问能够看见几个点. 解题分析:很明显,因为 N (1 ≤ N ≤ 1000) ,所以无论 N 为多 ...

  6. POJ3090_Visible Lattice Points【欧拉函数】

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

  7. 数论 - 欧拉函数模板题 --- poj 2407 : Relatives

    Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 Descri ...

  8. 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)

    题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...

  9. POJ3090 Visible Lattice Points

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

  10. 数论-欧拉函数-LightOJ - 1370

    我是知道φ(n)=n-1,n为质数  的,然后给的样例在纸上一算,嗯,好像是找往上最近的质数就行了,而且有些合数的欧拉函数值还会比比它小一点的质数的欧拉函数值要小,所以坚定了往上找最近的质数的决心—— ...

随机推荐

  1. JDK动态代理源码分析

    先抛出一个问题,JDK的动态代理为什么不支持对实现类的代理,只支持接口的代理??? 首先来看一下如何使用JDK动态代理.JDK提供了Java.lang.reflect.Proxy类来实现动态代理的,可 ...

  2. Struts 2 初步入门(二)

    Struts 2 动态方法调用 1.在HelloWorldAction中添加两个新的方法如下: import com.opensymphony.xwork2.ActionSupport; public ...

  3. 在vue项目中使用sass

    如果想开发移动端项目,那么适配的时候sass必不可缺,但是 npm  安装sass时候总是报错失败! 研究半天发现可以解决的方法,亲测有效 1.先换成淘宝镜像再安装 npm install -g cn ...

  4. Cmd管理员运行

    Cmd管理员运行     C:\Windows\System32  

  5. python 利用turtle库绘制五角星

    # -*- coding: utf-8 –*-import turtleimport math def draw_polygon(aTurtle, size=50, n=3): for i in ra ...

  6. 前端小菜鸡使用Vue+Element笔记(二)

    记录一下在使用Vue和Element做项目时遇到过的难点... 1.在 <el-table>表格中嵌入 select下拉选择框,以及 tooltip提示框的使用 主要定义格式如红色标记代码 ...

  7. java修饰符用法

    public:本类可使用,子类可使用,同一包内的类可使用,不同包内的类可使用 protected:本类可使用,子类可使用(不同包内的子类也可使用),同一包内的类可使用 default(当不写修饰符时) ...

  8. Java获取系统时间的四种方法

    1.Date day=new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); ...

  9. Serial interface (RS-232)

    转自:http://www.fpga4fun.com/SerialInterface.html A serial interface is a simple way to connect an FPG ...

  10. Centos7部署hadoop 3

    一:ssh免密登录: 1)vim /etc/ssh/sshd_config去掉注释或添加 RSAAuthentcation yes PubkeyAuthentication yes # Authent ...