POJ3090 Visible Lattice Points (数论:欧拉函数模板)
题目链接:传送门
思路:
所有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 (数论:欧拉函数模板)的更多相关文章
- [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< ...
- 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), ...
- zoj 2777 Visible Lattice Points(欧拉函数,基础)
题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<algo ...
- 【POJ】3090 Visible Lattice Points(欧拉函数)
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7705 Accepted: ...
- POJ 3090 Visible Lattice Points 【欧拉函数】
<题目链接> 题目大意: 给出范围为(0, 0)到(n, n)的整点,你站在(0,0)处,问能够看见几个点. 解题分析:很明显,因为 N (1 ≤ N ≤ 1000) ,所以无论 N 为多 ...
- POJ3090_Visible Lattice Points【欧拉函数】
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5653 Accepted: 333 ...
- 数论 - 欧拉函数模板题 --- poj 2407 : Relatives
Relatives Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11372 Accepted: 5544 Descri ...
- 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)
题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...
- POJ3090 Visible Lattice Points
/* * POJ3090 Visible Lattice Points * 欧拉函数 */ #include<cstdio> using namespace std; int C,N; / ...
- 数论-欧拉函数-LightOJ - 1370
我是知道φ(n)=n-1,n为质数 的,然后给的样例在纸上一算,嗯,好像是找往上最近的质数就行了,而且有些合数的欧拉函数值还会比比它小一点的质数的欧拉函数值要小,所以坚定了往上找最近的质数的决心—— ...
随机推荐
- 常用的flex知识 ,比起float position 好用不少
flex布局具有便捷.灵活的特点,熟练的运用flex布局能解决大部分布局问题,这里对一些常用布局场景做一些总结. web页面布局(topbar + main + footbar) 示例代码 要 ...
- WeRun is mini-app
WeRun is a mini-app within WeChat that allows users to monitor their daily step count. One of its mo ...
- Linux 硬件信息命令
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数cat /proc/cpuinfo| g ...
- ci框架memcached使用
首先第一步需要安装memcached扩展 安装方法这里就不叙述了 application/config/memcached.php配置 $config = array( 'default' => ...
- mac Nginx+CI出现404错误
主要是ci框架需要配置rewrite nginx.conf配置文件添加: location /wechat/ { if (!-e $request_filename) { rewrite ^/wech ...
- 【SQL】glob 和 like 的区别
LIKE 和 GLOB 都可以用来匹配通配符指定模式的文本值.如果搜索表达式与模式表达式匹配,LIKE 运算符将返回真(true),也就是 1 区别: (1)使用的通配符不一样 like: 百分号( ...
- Java正则表达式校验
package com.study.string; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * 正则表达 ...
- SWAP 简介
swap 交换分区,是存放在内存当中的临时数据(断电数据丢失) SWAP作用:当内存不足时会导致系统挂了,SWAP就是起到一个临时内存的作用,当内存不足时SWAP充当临时内存,防止系统挂掉
- IntelliJ IDEA导入Javax包(servlet-api.jar)
在初次使用 IntelliJ IDEA 中,当你使用javax.servlet包下的类时(例:javax.servlet.http.HttpServlet), 在你会发现在IntelliJ IDEA里 ...
- socket 编程通信实例
socket 编程通信实例:TCPserver: , ServerThread, ; WSADATA wsaData; ,), ; } ; } } ; g ...