uva 10820
/* 交表 _________________________________________________________________________________ #include <iostream>
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
#define fir first
#define sec second
#define pb(x) push_back(x)
#define mem(A, X) memset(A, X, sizeof A)
#define REP(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define rep(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))
#define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
typedef long long LL;
typedef unsigned long long ull;
typedef pair<long,long> pll; LL T,n;
const int mod=1e9+7;
const int maxn=1e5+10; const int size=50000;//1-10000的表
int phi[size+1];
void phi_table() // 1 到 n 的欧拉phi函数值表 ( O( nlg(lgn) ) )
{
for(int i=2;i<=size;i++)
{
phi[i]=0;
}
phi[1]=1;
for(int i=2;i<=size;i++)
{
if(!phi[i])
{
for(int j=i;j<=size;j+=i)
{
if(!phi[j]) phi[j]=j;
phi[j] = phi[j]/i*(i-1);
}
}
}
} int main()
{
freopen("in.txt","r",stdin);
phi_table();
while(cin>>n&&n)
//while(cin>>T)
{
//REP(kase,1,T) { }
LL ans=1;
REP(i,2,n)
ans+=2*phi[i];
cout<<ans<<endl; }
return 0;
} /*
note :
debug :
optimize:
*/
uva 10820的更多相关文章
- Uva 10820 交表
题目链接:https://uva.onlinejudge.org/external/108/10820.pdf 题意: 对于两个整数 x,y,输出一个函数f(x,y),有个选手想交表,但是,表太大,需 ...
- 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求,n以内的有序数对(x, y)互素的对数. 分析: 问题还可以继续转化. 根据对称性,我们可以假设x<y,当x=y时,满足条件的只有(1, 1 ...
- UVA 10820 - Send a Table 数论 (欧拉函数)
Send a Table Input: Standard Input Output: Standard Output When participating in programming contest ...
- uva 10820 (筛法构造欧拉函数)
send a table When participating in programming contests, you sometimes face the following problem: Y ...
- 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 欧拉函数模板题
这道题就是一道简单的欧拉函数模板题,需要注意的是,当(1,1)时只有一个,其他的都有一对.应该对欧拉函数做预处理,显然不会超时. #include<iostream> #include&l ...
- UVa 10820 - Send a Table
题目:找到整数区间[1.n]中全部的互质数对. 分析:数论,筛法,欧拉函数.在筛素数的的同一时候.直接更新每一个数字的欧拉函数. 每一个数字一定会被他前面的每一个素数筛到.而欧拉函数的计算是n*π(1 ...
- Uva 10820 Send a Table(欧拉函数)
对每个n,答案就是(phi[2]+phi[3]+...+phi[n])*2+1,简单的欧拉函数应用. #include<iostream> #include<cstdio> # ...
随机推荐
- stella mccartney falabella foldover tote a few eye observed
Lately, the particular Heyuan City Courtroom retrial, in order to commit the criminal offense of cou ...
- linux test 命令使用
1. 关于某个文件名的『类型』侦测(存在与否),如 test -e filename -e 该『文件名』是否存在?(常用) -f 该『文件名』是否为文件(file)?(常用) -d 该『文件名』是否为 ...
- hibernate中validate的使用(转)
原文链接:http://blog.csdn.net/xing_sky/article/details/8484551 首先是要加入下面两个包 hibernate-validator-4.1.0.Fin ...
- greendao 3.1.0在android studio中配置
1 项目根build.gradle classpath 'org.greenrobot:greendao-gradle-plugin:3.1.0' 2 app中build.gradle apply p ...
- Java IO流
File类 ·java.io.File类:文件和目录路径名的抽象表示形式,与平台无关 ·File能新建.删除.重命名文件和目录,但File不能访问文件内容本身.如果需要访问文件内容本身,则需要使用输入 ...
- Asp.net attributes collection
<?xml version="1.0" encoding="utf-8"?><root> <ContralNames> ...
- Why jsp?
Before the JSP come into the world . The CGI and servlet took the responsibility of generating dynam ...
- angular 指令作用域 scope
转载自:https://segmentfault.com/a/1190000002773689 下面我们就来详细分析一下指令的作用域. 在这之前希望你对AngularJS的Directive有一定的了 ...
- Linux的任务计划--cron入门
Linux操作系统定时任务系统 Cron 入门 cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业.由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动 ...
- Luogu 3396 权值分块
官方题解:这是一道论文题.集训队论文<根号算法——不只是分块>. 首先,题目要我们求的东西,就是下面的代码: for(i=k;i<=n;i+=p) ans+=value[i]; 即: ...