题目链接:传送门

思路:

  所有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. -L、-rpath和-rpath-link的区别

    链接器ld的选项有 -L,-rpath 和 -rpath-link,看了下 man ld,大致是这个意思: -L::  “链接”的时候去找的目录,也就是所有的 -lFOO 选项里的库,都会先从 -L ...

  2. windows 网络操作

    ver 命令 显示当前机器上的操作系统版本信息 ipconfig/release 释放IP地址 ipconfig/renew 重新获取IP地址 cmd下使用ssh 如果想在cmd中输入 ssh xx@ ...

  3. Ie11 的改变

    摘录地址:     http://www.4fang.net/content.jsp?id=30537 微软在上周刚刚发布了用于Windows 8.1上的首个Internet Explorer 11的 ...

  4. Spring Boot 如何极简入门?

    Spring Boot已成为当今最流行的微服务开发框架,本文是如何使用Spring Boot快速开始Web微服务开发的指南,我们将创建一个可运行的包含内嵌Web容器(默认使用的是Tomcat)的可运行 ...

  5. Five Great .NET Framework 4.5 Features (五大特性)

    [译].Net 4.5 的五项强大新特性   本文原文:Five Great .NET Framework 4.5 Features译者:冰河魔法师 目录 介绍 特性一:async和await 特性二 ...

  6. bzoj1096

    题解: 斜率优化dp 代码: #include<bits/stdc++.h> typedef long long ll; ; using namespace std; int n,l,r, ...

  7. C++ Templates 关于程序库的概念和通用工具

    using namespace std所谓的命名空间,就是一种将程序库名称封装起来的方法,它就像在程序库中竖立了一道围墙 标准程序库中有一部分,比如string classes,支持具体的错误处理,它 ...

  8. SqlServer2008备份与还原(完整图示版)

    一.备份 1.在需要备份的数据库上,右键——任务——备份,如下: 2.选择备份到哪个路径和备份名字: 点击“添加”,如下, 3.上面点击“确定”后,回到第一个页面,选中刚才添加的路径和文件名 4.左上 ...

  9. getchar getche getch的区别

    getchar 由宏实现:#define getchar() getc(stdin). getchar有一个int型的返回值.当程序调用getchar时.程序就等着用户按键.用户输入的字符被存放在键盘 ...

  10. 2.5 C++类class和结构体struct区别

    参考:http://www.weixueyuan.net/view/6337.html 总结: 在C++中,struct类似于class,在其中既可以定义数据成员,又可以定义成员函数. 在C++中,s ...