【bzoj2705】[SDOI2012]Longge的问题 欧拉函数
题目描述
输入
输出
样例输入
6
样例输出
15
题解
欧拉函数
易得知满足gcd(n,x)==i的小于等于n的x的个数为phi(n/i),
并且欧拉函数可以在O(√n)的时间内快速求出。。
于是可以先求出所有n的因子,再用欧拉函数得出答案。
由于因子是成对出现的,所以因子并不需要枚举到n,只需枚举到√n。如果i是n的因子,那么n/i也是n的因子,注意此时i*i==n不能算进答案内。
#include <cstdio>
typedef long long ll;
ll phi(ll x)
{
ll ans = x , t = x , i;
for(i = 2 ; i * i <= x ; i ++ )
{
if(t % i == 0) ans = ans * (i - 1) / i;
while(t % i == 0) t /= i;
}
if(t > 1) ans = ans * (t - 1) / t;
return ans;
}
int main()
{
ll n , i , ans = 0;
scanf("%lld" , &n);
for(i = 1 ; i * i <= n ; i ++ )
{
if(n % i == 0)
{
ans += i * phi(n / i);
if(i * i < n) ans += (n / i) * phi(i);
}
}
printf("%lld\n" , ans);
return 0;
}
【bzoj2705】[SDOI2012]Longge的问题 欧拉函数的更多相关文章
- BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)
题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1959 Solved: 1229[Submit][ ...
- [SDOI2012] Longge的问题 - 欧拉函数
求 \(\sum\limits_{i=1}^{n}gcd(i,n)\) Solution 化简为 \(\sum\limits_{i|n}^{n}φ(\dfrac{n}{i})i\) 筛出欧拉函数暴力求 ...
- bzoj 2705 [SDOI2012]Longge的问题——欧拉函数大水题
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2705 撕逼题.不就是枚举gcd==d,求和phi[ n/d ]么. 然后预处理sqrt (n ...
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- POJ 2480 Longge's problem 欧拉函数—————∑gcd(i, N) 1<=i <=N
Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6383 Accepted: 2043 ...
- Bzoj-2705 Longge的问题 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2705 题意: 求 sigma(gcd(i,n), 1<=i<=n<2^3 ...
- [SDOI2012]Longge的问题 欧拉反演_欧拉函数
Code: #include<cstdio> #include<algorithm> #include<cmath> #include<string> ...
随机推荐
- LeetCode 翻转链表
基本思路 从元首节点之后每次取一个节点,并将节点接到元首节点前面 代码实现 /** * Definition for singly-linked list. * struct ListNode { * ...
- css公共类
/*iOS弹性滚动*/ .scrolling{ position: absolute; width: 100%; height:100%; overflow-x:hidden; overflow-y: ...
- scala映射和元组
scala映射,是一对键值对,相当于java中的Map 对偶:由两个值构成的组,形式 : 值1->值2,值1和值2类型不一定要相同,可以理解为对偶就是一个key/value 映射就是对偶的集合 ...
- 3.2 进程间通信之fifo
一.引言 FIFO常被称为有名管道,不同于管道(pipe).pipe仅适用于“有血缘关系”的IPC.但FIFO还可以应用于不相关的进程的IPC.实际上,FIFO是Linux基础文件类型中的一种,是在读 ...
- 函数:引用file类对象及io类对象作为参数打印文本及显示文本
#include <iostream> #include <fstream> #include <cstdlib> using namespace std; voi ...
- R语言学习笔记(十三):零碎知识点(36-40)
36--diag() 如果它的参数是一个矩阵,它返回的是一个向量 如果它的参数是一个向量,它返回的是一个向量 如果它的参数是一个标量,它返回的是指定大小的单位矩阵 > diag(2) [,1] ...
- [Cracking the Coding Interview] 4.5 Validate BST
Implement a function to check if a binary tree is a binary search tree. 这道题很经典,让我们判断一棵树是不是二叉查找树.但是首先 ...
- 【转】mui 通过JSON动态的生成列表
<script type="text/template" id="radio-tigan"> <%for(var i=0;i<recor ...
- React+DvaJS 之 hook 路由权限控制
博客 学院 下载 GitChat TinyMind 论坛 APP 问答 商城 VIP 活动 招聘 ITeye 写博客 发Chat 登录注册 原 React+DvaJS 之 hook 路由权限控制 20 ...
- Android之线程安全的单例模式,Adapter注意事项之引用传值
线程安全的单例模式单位模式一般写法如下: public static FestivalLab mInstance; private FestivalLab() { } public static Fe ...