2705: [SDOI2012]Longge的问题

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://www.lydsy.com/JudgeOnline/problem.php?id=2705

Description

Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题。现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N)。

Input

一个整数,为N。

Output

一个整数,为所求的答案。

Sample Input

6

Sample Output

15

HINT

题意

题解

题解:http://hzwer.com/3470.html

题目中要求出∑gcd(i,N)(1<=i<=N)。

枚举n的约数k,令s(k)为满足gcd(m,n)=k,(1<=m<=n)m的个数,则ans=sigma(k*s(k)) (k为n的约数)

因为gcd(m,n)=k,所以gcd(m/k,n/k)=1,于是s(k)=euler(n/k)

phi可以在根号的时间内求出

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200051
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** ll n;
int m;
ll phi(ll x)
{
ll t=x;
for(ll i=;i<=m;i++)
{
if(x%i==)
{
t=t/i*(i-);
while(x%i==)x/=i;
}
}
if(x>)t=t/x*(x-);
return t;
}
int main()
{
cin>>n;
ll ans=;
m = sqrt(n);
for(int i=;i<=sqrt(n);i++)
{
if(n%i==)
{
ans+=i*phi(n/i);
if(i*i<n)
ans+=(ll)(n/i)*phi(i);
}
}
cout<<ans<<endl;
}

BZOJ 2705: [SDOI2012]Longge的问题 GCD的更多相关文章

  1. BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2553  Solved: 1565[Submit][ ...

  2. BZOJ 2705: [SDOI2012]Longge的问题

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 2554  Solved: 1566[Submit][ ...

  3. bzoj 2705: [SDOI2012]Longge的问题 歐拉函數

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1035  Solved: 669[Submit][S ...

  4. Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论

    2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 1959  Solved: 1229[Submit][ ...

  5. BZOJ 2705: [SDOI2012]Longge的问题( 数论 )

    T了一版....是因为我找质因数的姿势不对... 考虑n的每个因数对答案的贡献. 答案就是 ∑ d * phi(n / d) (d | n) 直接枚举n的因数然后求phi就行了. 但是我们可以做的更好 ...

  6. [bzoj]2705: [SDOI2012]Longge的问题[数论][数学][欧拉函数][gcd]

    [bzoj]P2705 OR [luogu]P2303 Longge的问题 Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需 ...

  7. bzoj 2705: [SDOI2012]Longge的问题——欧拉定理

    Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). Input 一 ...

  8. BZOJ 2705 [SDOI2012]Longge的问题(欧拉函数)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2705 [题目大意] 求出∑gcd(i,N)(1<=i<=N) [题解] $ ...

  9. [bzoj 2705][SDOI2012]Longge的问题(数学)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2705 分析: 设k为n的因数 设f[k]为gcd(x,n)==k的x的个数,容易知道a ...

随机推荐

  1. java运用FFMPEG视频转码技术

    基于windows系统安装FFMPEG转码技术 http://wenku.baidu.com/link?url=z4Tv3CUXxxzLpa5QPI-FmfFtrIQeiCYNq6Uhe6QCHkU- ...

  2. WdatePicker的一些用法

    在选择日期之后,再执行自己的另一个函数   onpicked: function () { LoadData(); }  <input type="text" class=& ...

  3. w3c盒子模型与ie盒子模型

    盒子模型是css的专有名词,用来描述页面设置中的各种属性,如内容(content).填充(padding).边框(border).边界(margin),由于这些属性拼在一起,与日常生活中的“盒子”很相 ...

  4. executeQuery,executeUpdate 和 execute 区别

    http://www.360doc.com/content/14/0315/09/16068204_360719186.shtml http://i-feng.iteye.com/blog/17066 ...

  5. POJ 1094 Sorting It All Out

    题意:给出m对关于n个字母的小于关系,输出通过这些关系能得到的结论,如果可以排序就输出至少知道第几个关系时就可以知道顺序,从小到大输出顺序:如果产生歧义就输出在第几个关系时出现歧义,如果不能得出准确的 ...

  6. [Everyday Mathematics]20150117

    设 $f:\bbR^{n\times n}\to\bbR$ 适合 $$\bex f(cA+B)=cf(A)+f(B),\quad f(AB)=f(BA),\quad\forall\ c\in\bbR, ...

  7. vim简单使用教程

    vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会对这个编辑器失去兴趣的.下面的文章翻译自<Learn Vim Progress ...

  8. 浏览器URL传参最大长度问题

    这几天为解决一个BUG头疼了一段时间,BUG现象如下: 一个选择人员的选择控件,当选择多个人时(50多个的时候),返回没有错误现象,而再一次打开的时候就报404错误.看到这个错误非常纳闷,无法下手,只 ...

  9. 机器学习中的数学(5)-强大的矩阵奇异值分解(SVD)及其应用

    版权声明: 本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com, 本文可以被全部的转载或者部分使用,但请注明出处,如果有问题,请联系wheeleast@gm ...

  10. Spark Streaming 架构

    图 1   Spark Streaming 架构图 组件介绍:‰ Network Input Tracker : 通 过 接 收 器 接 收 流 数 据, 并 将 流 数 据 映 射 为 输 入DSt ...