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),有个选手想交表,但是,表太大,需 ...
随机推荐
- 2018-2019-2 20162318《网络攻防技术》Exp5 MSF基础应用
1.实验内容 1.一个主动攻击实践,如ms08_067 2. 一个针对浏览器的攻击,如ms11_050) 3. 一个针对客户端的攻击,如Adobe 4. 成功应用任何一个辅助模块 2.基础问题回答 2 ...
- CI Weekly #15 | 据说新版 flow.ci Dashboard 界面很酷
好久不见 :) 最近工程师们卯足了劲,全新的 flow.ci dashboard 页面 已经与所有用户见面了.更快捷地创建项目,构建列表页面新增分支,Pull Request 界面:侧边栏新增构建任务 ...
- Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
- BZOJ 1008 [HNOI2008]越狱 排列组合
1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4788 Solved: 2060[Submit][Status] ...
- dos系统下的游戏~ 不断更新中
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #incl ...
- C# 传统的ToString
C# 传统的ToString DataRow dr=item; var str=dr["Name"]; str.ToString();//dr["Name"]= ...
- WPF中的ImageBrush常用方式
WPF的ImageBrush是一个比较常见也比较复杂的笔刷,它继承自图块笔刷(TileBrush).使用图块画笔绘制区域涉及以下三个组成部分:内容.基本图块和输出区域.基本输出过程如下图所示: 其中, ...
- Linux内核hlist数据结构分析
在内核编程中哈希链表hlist使用非常多,比方在openvswitch中流表的存储中就使用了(见[1]).hlist的表头仅有一个指向首节点的指针.而没有指向尾节点的指针,这样在有非常多个b ...
- 使用注册表优化终端、编辑器的中英字体混合显示,如「Consolas + 雅黑」「Monaco + 雅黑」
在终端.cmd.编辑器中偶尔会有中文字符出现,Windows下默认的点阵字体「宋体」和等宽英文字符放在一起非常违和.一个解决方法是下载混合字体,比如「Consolas + YAHEI hybrid」, ...
- AES加密时抛出java.security.InvalidKeyException: Illegal key size or default parametersIllegal key size or default parameters
使用AES加密时,当密钥大于128时,代码会抛出java.security.InvalidKeyException: Illegal key size or default parameters Il ...