bzoj2705
一个常用的结论(方法)
只要知道gcd(i,n)=L 的i的个数s,我们就能很轻易得出答案
gcd(i,n)=L
gcd(i/L,n/L)=1
不难得到这样的s=与n/L互质的个数=phi(n/L)
一个数的欧拉函数最坏情况是可以在O(sqrt(n))的复杂度中弄出来的
我们可以穷举L,只要从1穷举到根号n即可
var i:longint;
ans,n:int64; function phi(x:int64):int64;
var i:longint;
begin
phi:=;
for i:= to trunc(sqrt(n)) do
if x mod i= then
begin
phi:=phi*(i-);
x:=x div i;
while x mod i= do
begin
x:=x div i;
phi:=phi*i;
end;
if x= then break;
end;
if x> then phi:=phi*(x-);
end; begin
readln(n);
for i:= to trunc(sqrt(n)) do
if n mod i= then
begin
ans:=ans+phi(n div i)*i;
if i<>n div i then ans:=ans+phi(i)*(n div i);
end;
writeln(ans);
end.
bzoj2705的更多相关文章
- 【bzoj2705】 SDOI2012—Longge的问题
http://www.lydsy.com/JudgeOnline/problem.php?id=2705 (题目链接) 题意 给定一个整数N,你需要求出∑gcd(i, N)(1<=i <= ...
- BZOJ2705 SDOI2012 Longge的问题 【欧拉函数】
BZOJ2705 SDOI2012 Longge的问题 Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, ...
- [BZOJ2190&BZOJ2705]欧拉函数应用两例
欧拉函数phi[n]是表示1~n中与n互质的数个数. 可以用公式phi[n]=n*(1-1/p1)*(1-1/p2)*(1-1/p3)...*(1-1/pk)来表示.(p为n的质因子) 求phi[p] ...
- BZOJ2705: [SDOI2012]Longge的问题
Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). Input 一 ...
- Bzoj2705 Longge的问题
Time Limit: 3000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Description Longge的数学 ...
- Bzoj-2705 Longge的问题 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2705 题意: 求 sigma(gcd(i,n), 1<=i<=n<2^3 ...
- 【BZOJ2705】【Sdoi2012】Longge的问题
Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出\(\Sigma gcd(i, N) (1 \leq i \leq N ...
- 【欧拉函数】BZOJ2705: [SDOI2012]Longge的问题
Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). Solut ...
- BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)
题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...
随机推荐
- zigbee
IEEE802.15.4定义了两种器件:全功能器件(FFD,Full-FunctionDevice),和简化功能器件(RFD,Reduced-functionDevice) 协调器:(coordina ...
- MVC中实现部分内容异步加载
MVC中实现部分内容异步加载 action中定义一个得到结果集的方法 public ActionResult GetItemTree(string title, int itemid, int? pa ...
- [linux] 系统管理常用命令
1.查看某个软件是否安装: rpm -qa|grep software_name 2.top命令,显示系统的动态视图,q退出 3.ps aux|grep process_name 显示正在运行的进程 ...
- c#保存textbox中的字符串到txt文件中
/********************** 保存接收按钮 *****************************/ private void SavetxData_Click(object s ...
- C++ 数组的地址问题学习随笔
二维数组额地址问题学习,本文学习内容参考:http://blog.csdn.net/wwdlk/article/details/6322439 #include<iostream> usi ...
- zlib压缩解压示例
#include <stdio.h> #include <string.h> #include <assert.h> #include "zlib.h&q ...
- CSS Masking(翻译)
原文地址:http://www.html5rocks.com/en/tutorials/masking/adobe/ 关于计算机图形,两种常见的操作是:cliping(裁剪) and masking ...
- Mysql DOC阅读笔记
Mysql DOC阅读笔记 转自我的Github Speed of SELECT Statements 合理利用索引 隔离调试查询中花费高的部分,例如函数调用是在结果集中的行执行还是全表中的行执行 最 ...
- js生成随机字符串或者随机数
//返回一个指定范围内的随机数 function createRandomNum(Min,Max){ let Range = Max - Min; let Rand = Math.random(); ...
- 移动web问题小结
Meta标签: <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalab ...