//author Eterna
#define Hello the_cruel_world!
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#include<complex>
#include<numeric>
#include<unordered_map>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define Pi acos(-1.0)
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))
#define pb(x) push_back(x)
#define lowbit(x) (x & -x)
#define FRIN freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\in.txt", "r", stdin)
#define FROUT freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\out.txt", "w", stdout)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define outd(x) printf("%d\n", x)
#define outld(x) printf("%lld\n", x)
#define il inline
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 1e6;
const int INF = 0x7fffffff;
const int mod = 1e9 + ;
const double eps = 1e-;
inline int read_int() {
char c;
int ret = , sgn = ;
do { c = getchar(); } while ((c < '' || c > '') && c != '-');
if (c == '-') sgn = -; else ret = c - '';
while ((c = getchar()) >= '' && c <= '') ret = ret * + (c - '');
return sgn * ret;
}
inline ll read_ll() {
char c;
ll ret = , sgn = ;
do { c = getchar(); } while ((c < '' || c > '') && c != '-');
if (c == '-') sgn = -; else ret = c - '';
while ((c = getchar()) >= '' && c <= '') ret = ret * + (c - '');
return sgn * ret;
}
int phi[maxn + ], prime[maxn + ];
ll sum[maxn + ];
bool is_prime[maxn + ];
void init(int n, int cnt = ) {
for (int i = ; i <= n; ++i)is_prime[i] = true;
for (int i = ; i <= n; ++i) {
if (is_prime[i])prime[++cnt] = i, phi[i] = i - ;
for (int j = ; j <= cnt && i * prime[j] <= n; ++j) {
is_prime[i * prime[j]] = false;
if (i % prime[j])phi[i * prime[j]] = phi[i] * phi[prime[j]];
else {
phi[i * prime[j]] = phi[i] * prime[j];
break;
}
}
}
for (int i = ; i <= n; ++i)for (int j = ; j * i <= n; ++j)sum[i * j] += i * phi[j];
for (int i = ; i <= n; ++i)sum[i] += sum[i - ];
}
int n;
int main()
{
init(maxn);
while (n = read_int())printf("%lld\n", sum[n]);
//system("pause");
return ;
}

SP3871 GCDEX - GCD Extreme的更多相关文章

  1. 洛谷 - SP3871 GCDEX - GCD Extreme - 莫比乌斯反演

    易得 $\sum\limits_{g=1}^{n} g \sum\limits_{k=1}^{n} \mu(k) \lfloor\frac{n}{gk}\rfloor \lfloor\frac{n}{ ...

  2. spoj 3871. GCD Extreme 欧拉+积性函数

    3871. GCD Extreme Problem code: GCDEX Given the value of N, you will have to find the value of G. Th ...

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

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Problem JGCD Extreme (II)Input: Standard ...

  4. UVA 11426 - GCD - Extreme (II) (数论)

    UVA 11426 - GCD - Extreme (II) 题目链接 题意:给定N.求∑i<=ni=1∑j<nj=1gcd(i,j)的值. 思路:lrj白书上的例题,设f(n) = gc ...

  5. 【UVa11426】GCD - Extreme (II)(莫比乌斯反演)

    [UVa11426]GCD - Extreme (II)(莫比乌斯反演) 题面 Vjudge 题解 这.. 直接套路的莫比乌斯反演 我连式子都不想写了 默认推到这里把.. 然后把\(ans\)写一下 ...

  6. UVA11426 GCD - Extreme (II) (欧拉函数/莫比乌斯反演)

    UVA11426 GCD - Extreme (II) 题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 10 100 200000 0 输出样例#1: 67 13 ...

  7. GCD - Extreme (II) for(i=1;i<N;i++) for(j=i+1;j<=N;j++) { G+=gcd(i,j); } 推导分析+欧拉函数

    /** 题目:GCD - Extreme (II) 链接:https://vjudge.net/contest/154246#problem/O 题意: for(i=1;i<N;i++) for ...

  8. USACO GCD Extreme(II)

    题目大意:求gcd(1,2)+gcd(1,3)+gcd(2,3)+...+gcd(n-1,n) ---------------------------------------------------- ...

  9. 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) 此 ...

随机推荐

  1. 活代码LINQ——04

    一.主模块代码: 'Fig.4.16:GradeBookTest.vb 'Create and manipulate a GradeBook object;illustrate validation ...

  2. mysql插入中文报错的问题

    报错:1366, "Incorrect string value: '\\xE6\\xB7\\xB1\\xE5\\x85\\xA5...' for column ' 由于公司原因之前一直在使 ...

  3. angular 定时函数

    注入$interval,$timeout   服务 2.定义函数 var aa = $interval(function(){ $timout(function(){ ..... }) },,定时时间 ...

  4. 深度解析synchronized的实现原理(并发一)

    一.synchronized实现原理 1.synchronized实现同步的基础: 1).普通同步方法:锁是当前实例对象 2).静态同步方法:锁是当前类的class对象 3).同步方法块:锁是括号里面 ...

  5. c++ 指针与const的三种组合

    三种形式 const int a=1; int b=2: 1 const int * ptr1=&a; 2  int * const ptr2 = b; 3 const int * const ...

  6. 杭电ACM1007

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. zookeeper集群的搭建(个人实践可行)

    linux 上面 zookeeper 集群(最少3个节点192.168.204.128.192.168.204.129.192.168.204.130)安装 1.创建文件夹/usr/local/zoo ...

  8. shell_base

    1.使用if_then语句if command then commands fi 先运行if后面的命令,如果命令的退出状态是0(成功执行命令),就将执行then后面,fi前面的所有命令.否则就跳到fi ...

  9. SpringIOC容器装配Bean

    Spring 的core Container(Spring的核心容器)有四大部分:bean.context.core.expression 在进行Bean的配置时候,需要添加四个jar包 如下: 分别 ...

  10. 推理机Jess,Racer,Jena

    推理机 Jess(Java Expert Shell System)是基于Java语言的CLISP推理机. CLISP是基于产生式的前向推理引擎,许多上层的推理任务,都要映射到这个推理引擎上来运行. ...