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> # ...
随机推荐
- Python 3.x 使用csv模块写入数据
with open(fileName,'w',newline='') as f: self.fileNames = ['timestamp','elapsedtime'] writer = csv.D ...
- 【转】Linux下如何清除系统日志
使用过Windows的人都知道,在使用windows系统的过程中系统会变得越来越慢.而对于Windows下饱受诟病的各种垃圾文件都需要自己想办法删除,不然系统将会变得越来越大,越来越迟钝!window ...
- C语言-预估校正法求常微分方程
#include<stdio.h> #include<math.h> #define n 14 int main(){ double a = 0.0, b = 1.4,h,m= ...
- c语言函数指针
#include <stdio.h> typedef void (*intFunc)(int i); void test1(int age) { printf("test1:%d ...
- 学习git config配置文件
设置 git status的颜色. git config --global color.status auto 一.Git已经在你的系统中了,你会做一些事情来客户化你的Git环境.你只需要做这些设置一 ...
- Linux 终端常用快捷键
Tab 自动补全 Ctrl+L 清屏 Ctrl+A 移动到头 Ctrl+E 移动到尾 Ctrl+左键头 左移一个单词 Ctrl+右箭头 右移一个单词 Ctrl+U 删除左边所有字符 Ctrl+K 删除 ...
- GoldenGate Studio 12.2.1.1发布
OGG studio是一款图形化OGG配置部署产品,其主要特性:1. 逻辑层面设计OGG,不需要了解OGG细节:2. 最值实践加快常用场景的配置:3. 使用拖拉映射,自动匹配源和目标对象:4. 一键部 ...
- jbox用法
详见 http://www.jjsp.gov.cn:8888/js/jbox-v2.3/jbox-demo2.html
- 解决maven生成的web项目下的servlet.jar与tomcat自带servlet.jar冲突的问题
使用maven生成web工程后,编译需要下servlet-api.jar和jsp-api.jar文件. pom文件中的写法为: <dependency> <groupId>ja ...
- JAVA Arrays.binarySearch
转自:http://blog.csdn.net/somebodydie/article/details/8229343 package com.jaky; import java.util.*; pu ...