对每个n,答案就是(phi[2]+phi[3]+...+phi[n])*2+1,简单的欧拉函数应用。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<deque>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const double eps=1e-;
const int INF=;
const int maxn=+;
int n,phi[maxn];
int main()
{
//freopen("in2.txt","r",stdin);
memset(phi,,sizeof(phi));
for(int i=;i<maxn;i++)
{
if(phi[i]==)
{
for(int j=i;j<maxn;j+=i)
{
if(phi[j]==) phi[j]=j;
phi[j]=phi[j]/i*(i-);
}
}
}
while(scanf("%d",&n)==&&n)
{
LL ans=;
for(int i=;i<=n;i++)
{
//cout<<i<<'-'<<phi[i]<<endl;
ans+=(LL)phi[i]*;
}
cout<<ans<<endl;
}
return ;
}

Uva 10820 Send a Table(欧拉函数)的更多相关文章

  1. UVa 10820 (打表、欧拉函数) Send a Table

    题意: 题目背景略去,将这道题很容易转化为,给出n求,n以内的有序数对(x, y)互素的对数. 分析: 问题还可以继续转化. 根据对称性,我们可以假设x<y,当x=y时,满足条件的只有(1, 1 ...

  2. UVa10820 Send a Table[欧拉函数]

    Send a TableInput: Standard Input Output: Standard Output When participating in programming contests ...

  3. uva 10820 (筛法构造欧拉函数)

    send a table When participating in programming contests, you sometimes face the following problem: Y ...

  4. UVA 10820 - Send a Table 数论 (欧拉函数)

    Send a Table Input: Standard Input Output: Standard Output When participating in programming contest ...

  5. UVa 10820 - Send a Table(欧拉函数)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. UVA 11424 GCD - Extreme (I) (欧拉函数+筛法)

    题目:给出n,求gcd(1,2)+gcd(1,3)+gcd(2,3)+gcd(1,4)+gcd(2,4)+gcd(3,4)+...+gcd(1,n)+gcd(2,n)+...+gcd(n-1,n) 此 ...

  7. UVA 11426 GCD - Extreme (II) (欧拉函数+筛法)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/O 题意是给你n,求所有gcd(i , j)的和,其中 ...

  8. UVa 10214 (莫比乌斯反演 or 欧拉函数) Trees in a Wood.

    题意: 这道题和POJ 3090很相似,求|x|≤a,|y|≤b 中站在原点可见的整点的个数K,所有的整点个数为N(除去原点),求K/N 分析: 坐标轴上有四个可见的点,因为每个象限可见的点数都是一样 ...

  9. UVA 11426 GCD - Extreme (II) 欧拉函数

    分析:枚举每个数的贡献,欧拉函数筛法 #include <cstdio> #include <iostream> #include <ctime> #include ...

随机推荐

  1. DFS应用——找出无向图的割点

    [0]README 0.1) 本文总结于 数据结构与算法分析, 源代码均为原创, 旨在 理解 "DFS应用于找割点" 的idea 并用源代码加以实现: 0.2) 必须要事先 做个s ...

  2. PHP-Manual的学习----【语言参考】----【类型】-----【NULL】

    2017年8月24日11:34:061.特殊的 NULL 值表示一个变量没有值.NULL 类型唯一可能的值就是 NULL. 2.在下列情况下一个变量被认为是 NULL: ◦ 被赋值为 NULL. ◦ ...

  3. 安卓常用的xml控件配件的使用包含shape,declare-styleable、selector

    今天就讲我所遇到的常用到的一些通过xml文件制作的背景效果,以后用到的话就直接使用啦!哈哈,我一向就是这么懒! 接下来,就开始介绍了 1.shape的使用,可以混合使用 xml控件配置属性 andro ...

  4. K-Piggy-Bank

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. vs05字节对齐问题又一不小心就弄去了我一个下午的时间

    由于一字节的对齐问题,我调一个库调了我基本一个下午..... 犯错其实并不可怕, 可怕的是你一犯再犯...... 这也算得上是难能可贵... /Zp (Struct Member Alignment) ...

  6. JS表单提交

    测试一: function submit(){var form1=document.getElementById("form1")form1.action="/manag ...

  7. Kafka具体解释二、怎样配置Kafka集群

    Kafka集群配置比較简单,为了更好的让大家理解.在这里要分别介绍以下三种配置 单节点:一个broker的集群 单节点:多个broker的集群 多节点:多broker集群 一.单节点单broker实例 ...

  8. windows下安装PyQt4

    第一步:确认自己电脑上的Python版本.然后下载对应的.whl文件下载 第二步:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4上下载对应版本版本的 ...

  9. SAP文件夹的判断与创建

    [转自 http://blog.csdn.net/saphome/article/details/6956918] SAP文件夹存在的判断与创建 2010-08-29 20:15 相关函数:WS_QU ...

  10. Redis持久化——问题定位与优化(三)

    核心知识点: 1.fork操作 a.在RDB或AOF重写时,会执行fork操作创建子进程,fork操作是一个重量级操作. b.改善fork操作耗时的手段:避免使用Xen.配置Redis实例最大使用内存 ...