思路:

虽然看到题目就想到了用欧拉函数做,但就是不知道怎么做...

当a b互质时GCD(a,b)= 1,由此我们可以推出GCD(k*a,k*b)= k。设ans[i]是1~i-1与i的GCD之和,所以最终答案是将ans[0]一直加到ans[n]。当 k*i==j 时,ans[j]=k*euler[i]。

看完题解瞬间领悟:神奇海螺

突然忘记欧拉函数是什么:欧拉函数

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<queue>
#include<cmath>
#include<string>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<iostream>
#include<algorithm>
#define INF 0x3f3f3f3f
#define ll long long
const int N=4000005;
const int M=4000000;
const int MOD=1000;
using namespace std;
ll ans[N];
ll euler[N];
void get(){
memset(ans,0,sizeof(ans));
for(int i=1;i<=M;i++){
euler[i]=i;
}
for(int i=2;i<=M;i++){
if(euler[i]==i){ //i是质数
for(int j=i;j<=M;j+=i){
euler[j]=euler[j]/i*(i-1);
}
}    //得到与i互质的个数
for(int k=1;k*i<=M;k++){    
ans[k*i]+=k*euler[i];
}
}
for(int i=2;i<=M;i++){
ans[i]+=ans[i-1];
}
}
int main(){
get();
int T,num=1,n;
while(~scanf("%d",&n) && n){
printf("%lld\n",ans[n]);
}
return 0;
}

UVA 11426 GCD - Extreme (II) (欧拉函数)题解的更多相关文章

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

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

  2. UVA 11426 GCD - Extreme (II)(欧拉函数打表 + 规律)

    Given the value of N, you will have to find the value of G. The definition of G is given below:Here ...

  3. uva 11426 GCD - Extreme (II) (欧拉函数打表)

    题意:给一个N,和公式 求G(N). 分析:设F(N)= gcd(1,N)+gcd(2,N)+...gcd(N-1,N).则 G(N ) = G(N-1) + F(N). 设满足gcd(x,N) 值为 ...

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

    Given the value of N, you will have to find the value of G. The definition of G is given below:G =i< ...

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

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

  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. UVA11426 GCD - Extreme (II) (欧拉函数/莫比乌斯反演)

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

  8. UVA11426 GCD - Extreme (II)---欧拉函数的运用

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

  9. UVA11426 GCD - Extreme (II) —— 欧拉函数

    题目链接:https://vjudge.net/problem/UVA-11426 题意: 求 ∑ gcd(i,j),其中 1<=i<j<=n . 题解:1. 欧拉函数的定义:满足 ...

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

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

随机推荐

  1. JS中"属性"的用法

    JS的属性和C#有相似之处  ! 使用get和set来进行属性的获取和设置 var obj={ a:"1", get age(){ return obj.a; }, set age ...

  2. eclipse的new server里tomcat7.0根本选不上解决方法

    创建Tomcat v7.0 Server 不能进行下一步. 解决方法: 1.退出 eclipse 2.到[工程目录下]/.metadata/.plugins/org.eclipse.core.runt ...

  3. BUG笔记:Win XP IE8下HTML Parsing Error: Unable to modify the parent container element before the child

    [Bug描述]Windows XP IE8的某些版本下页面只显示一部分,其余为空白.IE左下角有惊叹号报错标志,点开后显示字符如下: HTML Parsing Error: Unable to mod ...

  4. "portrait"(竖屏) "landscape"(横屏) css设置

    取决于浏览器或者设备的方向,HTML元素总是会有"portrait"(竖屏) "landscape"(横屏) class. 你可以在css中如下使用它们: .p ...

  5. 前端 HTML body标签相关内容 常用标签 换行标签 br

    换行标签 <br> <br>标签用来将内容换行,其在HTML网页上的效果相当于我们平时使用word编辑文档时使用回车换行. 在第一行中间加上br <!DOCTYPE ht ...

  6. Java-idea-生成for循环

    itar 生成array for代码块 for (int i = 0; i < array.length; i++) { = array[i]; } itco 生成Collection迭代 fo ...

  7. 3.cassandra遇到内存占用过高的问题

    目前cssandra的内存分配如下: https://docs.datastax.com/en/cassandra/2.1/cassandra/operations/ops_tune_jvm_c.ht ...

  8. 关于Python类属性与实例属性的讨论

    标题名字有点长. 之所以想写这个文章是因为碰巧看到网上一篇关于Pyhon中类属性及实例属性区别的帖子.因为我之前也被这个问题困扰过,今天碰巧看到了这篇帖子,发现帖子的作者只是描述了现象,然后对原因的解 ...

  9. oj2892(字典树)

    一改时间以后WA了,我就知道这题是考字典树,可惜代码怎么也不会敲了,郁闷. #include <stdio.h>#include <string.h>#include < ...

  10. 【Cocos2dx 3.3 Lua】触屏事件

    cocos2dx 3.x触屏时间分为单点触摸和多点触摸:     单点触摸:(即只有注册的Layer才能接收触摸事件)      多点触摸点单用法(多个Layer获取屏幕事件):           ...