UVA11426 GCD - Extreme (II)---欧拉函数的运用
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=473&problem=2421&mosmsg=Submission+received+with+ID+13800900
Given the value of N, you will have to find the value of G. The definition of G is given below:
Input
The input file contains at most 100 lines of inputs. Each line contains an integer N (1 < N < 4000001).
The meaning of N is given in the problem statement. Input is terminated by a line containing a single
zero.
Output
For each line of input produce one line of output. This line contains the value of G for the correspondingN. The value of G will fit in a 64-bit signed integer.
Sample Input
10
100
200000
0
Sample Output
67
13015
143295493160
我们假设b[n]表示1到n-1与n的gcd的和,那么G[n]=G[n-1]+b[n];
a[i]表示与gcd(n, x)= i 的x的个数;b[n]=sum( a[i] * i ) , 所以我们只需求a[i]即可;根据gcd(n, x)=i ----->gcd(n/i, x/i) = 1,
因此仅仅要求出欧拉函数phi(n / i),就能够得到与n / i互质的个数,从而求出gcd(x , n) = i的个数,这样总体就能够求解了
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std; #define N 4000001
typedef long long LL; LL a[N], b[N], dp[N]; int main()
{
for(int i=; i<N; i++)///欧拉打表;
{
if(!a[i])
{
for(int j=i; j<N; j+=i)
{
if(!a[j]) a[j]=j;
a[j]=a[j]/i*(i-);
}
}
} for(int i=; i<N; i++)///[1,n-1]中所有的数与n的gcd的和
for(int j=i*; j<N; j+=i)
b[j] += a[j/i]*i; for(int i=; i<N; i++)
dp[i]=dp[i-]+b[i]; int n;
while(scanf("%d", &n), n)
{
printf("%lld\n", dp[n]);
}
return ;
}
UVA11426 GCD - Extreme (II)---欧拉函数的运用的更多相关文章
- UVA11426 GCD - Extreme (II) (欧拉函数/莫比乌斯反演)
UVA11426 GCD - Extreme (II) 题目描述 PDF 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 10 100 200000 0 输出样例#1: 67 13 ...
- UVA11426 GCD - Extreme (II) —— 欧拉函数
题目链接:https://vjudge.net/problem/UVA-11426 题意: 求 ∑ gcd(i,j),其中 1<=i<j<=n . 题解:1. 欧拉函数的定义:满足 ...
- UVA 11426 GCD - Extreme (II) (欧拉函数+筛法)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/O 题意是给你n,求所有gcd(i , j)的和,其中 ...
- 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 ...
- 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) 值为 ...
- 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< ...
- UVA 11426 GCD - Extreme (II) 欧拉函数
分析:枚举每个数的贡献,欧拉函数筛法 #include <cstdio> #include <iostream> #include <ctime> #include ...
- 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) 此 ...
- GCD - Extreme(欧拉函数变形)
题目链接:https://vjudge.net/problem/UVA-11426 题目大意: 给出整数n∈[2,4000000],求解∑gcd(i,j),其中(i,j)满足1≤i<j≤n. 的 ...
随机推荐
- 浏览器 本地预览图片 window.url.createobjecturl
第一种方式 <script type="text/javascript"> function setImagePreview() { var docObj = docu ...
- 16位结构的CPU,8086给出物理地址的方法
.16位结构的CPU 概括地讲,16位结构(16位机,字长为16位等常见说法,与16位结构的含义相同)描述了一个CPU具有下面几方面结构特性: 1.运算器一次最多可以处理16位的数据结构 2.寄存器的 ...
- spoj687(后缀数组)
http://www.spoj.com/problems/REPEATS/ 题意:给一串字符,需要你求这一串字符中有连续重复的字符的重复次数....... 思路:这是和poj3693一种类型的题目.. ...
- 最新PHPcms9.6.0 任意文件上传漏洞
在用户注册处抓包: 然后发送到repeater POC: siteid=&modelid=&username=z1aaaac121&password=aasaewee311as ...
- C++中数字和字符串的转换
1.字符串数字之间的转换 (1)string --> char * string str("OK"); char * p = str.c_str(); (2)char ...
- 常用的easyui使用方法
-------datagrid 1.获取某行的行号(row)tdg.datagrid('getRowIndex',rows)2.通过行号移除该行tdg.datagrid('deleteRow',ind ...
- 第二百四十五节,Bootstrap标签页和工具提示插件
Bootstrap标签页和工具提示插件 学习要点: 1.标签页 2.工具提示 本节课我们主要学习一下 Bootstrap 中的标签页和工具提示插件. 一.标签页选项卡 标签页也就是通常所说的选项卡功能 ...
- 集成学习AdaBoost算法——学习笔记
集成学习 个体学习器1 个体学习器2 个体学习器3 ——> 结合模块 ——>输出(更好的) ... 个体学习器n 通常,类似求平均值,比最差的能好一些,但是会比最好的差. 集成可能提 ...
- Boost-date_time库学习
最近开了boost库的学习,就先从日期-时间库开始吧,boost的date_time库是一个很强大的时间库,用起来还是挺方便的. 以下代码只是入门级的简单学习,更详细的资料参考boost源码. C+ ...
- Oracle 10g 数据库手动创建步骤
Oracle 数据库手动创建步骤 编写初始化参数文件 设置操作系统环境变量 创建实例 以管理员身份连接数据库 启动实例 create database 创建数据库 运行数据字典脚本 Oracle的网络 ...