UVa 10820 - Send a Table
题目:找到整数区间[1。n]中全部的互质数对。
分析:数论,筛法,欧拉函数。在筛素数的的同一时候。直接更新每一个数字的欧拉函数。
每一个数字一定会被他前面的每一个素数筛到。而欧拉函数的计算是n*π(1-1/pi);
当中,pi是n的素数因子,所以能够利用筛法来计算欧拉函数,然后求和;
注意,这时求出的欧拉函数为全部小于n的数m与n的互质对,所以要乘以2;
(1,1)仅仅有一个,所以还要减掉1。
说明:打表计算,查询输出。
#include <iostream>
#include <cstdlib> using namespace std; int euler[50001];
int sums[50001];
int used[50001]; int main()
{
for (int i = 0 ; i < 50001 ; ++ i) {
used[i] = 0;
euler[i] = i;
} for (int i = 2 ; i < 50001 ; ++ i)
if (!used[i]) {
for (int j = i ; j < 50001 ; j += i) {
used[j] = 1;
euler[j] = euler[j]/i*(i-1);
}
} sums[0] = 0;
for (int i = 1 ; i < 50001 ; ++ i)
sums[i] = sums[i-1]+euler[i]; int n;
while (cin >> n && n)
cout << 2*sums[n]-1 << endl; return 0;
}
UVa 10820 - Send a Table的更多相关文章
- UVA 10820 - Send a Table 数论 (欧拉函数)
Send a Table Input: Standard Input Output: Standard Output When participating in programming contest ...
- UVA 10820 Send a Table euler_phi功能
除1,1其他外国x,y不等于 为 x<y 案件 一切y有phi(y)组合 F[x]= phi(i) 2<=i<=x 结果为 2*F[x]+1 Problem A Send a Tab ...
- UVa 10820 - Send a Table(欧拉函数)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- Uva 10820 Send a Table(欧拉函数)
对每个n,答案就是(phi[2]+phi[3]+...+phi[n])*2+1,简单的欧拉函数应用. #include<iostream> #include<cstdio> # ...
- UVa10820 Send a Table[欧拉函数]
Send a TableInput: Standard Input Output: Standard Output When participating in programming contests ...
- uva 10820 (筛法构造欧拉函数)
send a table When participating in programming contests, you sometimes face the following problem: Y ...
- 【UVA 10820】Send a Table(欧拉函数)
Description When participating in programming contests, you sometimes face the following problem: Yo ...
- UVa 10820 (打表、欧拉函数) Send a Table
题意: 题目背景略去,将这道题很容易转化为,给出n求,n以内的有序数对(x, y)互素的对数. 分析: 问题还可以继续转化. 根据对称性,我们可以假设x<y,当x=y时,满足条件的只有(1, 1 ...
- Uva 10820 交表
题目链接:https://uva.onlinejudge.org/external/108/10820.pdf 题意: 对于两个整数 x,y,输出一个函数f(x,y),有个选手想交表,但是,表太大,需 ...
随机推荐
- [BZOJ2683]简单题/[BZOJ1176][BalkanOI2007]Mokia
[BZOJ2683]简单题 题目大意: 一个\(n\times n(n\le5\times10^5)\)的矩阵,初始时每个格子里的数全为\(0\).\(m(m\le2\times10^5)\)次操作, ...
- Python文件类型
Python的文件类型分为三种:源代码.字节代码.优化代码. 1. 源代码 Python源代码文件,即py脚本文件,由 python.exe 解释,可在控制台下运行.pyw脚本文件是图形用户接口 ...
- Alpha冲刺(1/10)——追光的人
1.队友信息 队员学号 队员博客 221600219 小墨 https://www.cnblogs.com/hengyumo/ 221600240 真·大能猫 https://www.cnblogs. ...
- Linux知识(7)----远程登录 和远程拷贝
一.远程登录 1.安装客户端 可以使用ssh(Secure Shell(缩写为SSH))来进行远程的登录.安装ssh的命令为: sudo apt-get install openssh-server ...
- Hyper-V创建固定大小虚拟机
1.新建硬盘 点击确定,就创建好了一个固定大小的vhd文件,下面我们开始创建虚拟机. 2.创建虚拟机 输入虚拟机名称 选择第一代虚拟机 我这里给虚拟机分配512MB内存 网络配置 在这之前我们已经创建 ...
- oracle中的术语
数据库:数据库是实实在在存在的文件,一个数据库文件体系中大致包含(数据文件DBF.控制文件CTL.日志文件LOG) 数据库实例:每个数据库都会有一个数据库实例与之对应,外界环境要通过与数据库实例的交互 ...
- FolderSync Instant sync 即时同步
Folderpairs - Edit folderpair - Sync options - Instant sync Select this for instant sync on change. ...
- How to read out WhatsApp messages with Tasker and react on their content in real time
http://technologyworkroom.blogspot.sg/2013/05/tasker-how-to-read-out-whatsapp.html Tasker can read o ...
- Tasker to proximity screen on
in my previous entry, i posed an idea how to use the built-in proximity sensor to turn the screen of ...
- [Asp.net MVC]Html.AntiForgeryToken()
CSRF(Cross-site request forgery)跨站请求伪造,也被称为“One Click Attack”或者Session Riding,通常缩写为CSRF或者XSRF,是一种对网站 ...