51nod--1240莫比乌斯函数 (数论)
题目:
1240 莫比乌斯函数
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注
莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出。梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号。(据说,高斯(Gauss)比莫比乌斯早三十年就曾考虑过这个函数)。
具体定义如下:
如果一个数包含平方因子,那么miu(n) = 0。例如:miu(4), miu(12), miu(18) = 0。
如果一个数不包含平方因子,并且有k个不同的质因子,那么miu(n) = (-1)^k。例如:miu(2), miu(3), miu(30) = -1,miu(1), miu(6), miu(10) = 1。
给出一个数n, 计算miu(n)。
Input
输入包括一个数n,(2 <= n <= 10^9)
Output
输出miu(n)。
Input示例
5
Output示例
-1
分析:
也就是数论中莫比乌斯函数, 对于一个n, 就像分解质因数那样, 处理即可。
实现:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL Miu( LL n ) { /// 莫比乌斯函数板子。
LL m = 1;
for(LL i = 2; i * i <= n; ++i) {
if(n % i == 0) {
m *= -1;
LL k = 0;
do {
k++;
if(k > 1) { m = 0; break; }
n /= i;
} while ( n % i == 0);
}
}
if(n > 1) m *= -1;
return m;
}
int main() {
LL n;
while(cin >> n) {
cout << Miu(n) << endl;
}
}
51nod--1240莫比乌斯函数 (数论)的更多相关文章
- 51nod 1240 莫比乌斯函数
题目链接:51nod 1240 莫比乌斯函数 莫比乌斯函数学习参考博客:http://www.cnblogs.com/Milkor/p/4464515.html #include<cstdio& ...
- 51nod 1240 莫比乌斯函数【数论+莫比乌斯函数】
1240 莫比乌斯函数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用 ...
- 51nod 1244 莫比乌斯函数之和
题目链接:51nod 1244 莫比乌斯函数之和 题解参考syh学长的博客:http://www.cnblogs.com/AOQNRMGYXLMV/p/4932537.html %%% 关于这一类求积 ...
- 51 Nod 1240 莫比乌斯函数
1240 莫比乌斯函数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使 ...
- 51nod 1244 莫比乌斯函数之和 【杜教筛】
51nod 1244 莫比乌斯函数之和 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号.具体定义如下: 如果一个数包含 ...
- [51Nod 1244] - 莫比乌斯函数之和 & [51Nod 1239] - 欧拉函数之和 (杜教筛板题)
[51Nod 1244] - 莫比乌斯函数之和 求∑i=1Nμ(i)\sum_{i=1}^Nμ(i)∑i=1Nμ(i) 开推 ∑d∣nμ(d)=[n==1]\sum_{d|n}\mu(d)=[n== ...
- 51nod 1244 莫比乌斯函数之和(杜教筛)
[题目链接] http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 [题目大意] 计算莫比乌斯函数的区段和 [题解] 利 ...
- 51Nod.1244.莫比乌斯函数之和(杜教筛)
题目链接 map: //杜教筛 #include<map> #include<cstdio> typedef long long LL; const int N=5e6; in ...
- 51nod 1244 莫比乌斯函数之和 【莫比乌斯函数+杜教筛】
和bzoj 3944比较像,但是时间卡的更死 设\( f(n)=\sum_{d|n}\mu(d) g(n)=\sum_{i=1}^{n}f(i) s(n)=\sum_{i=1}^{n}\mu(i) \ ...
- 51Nod 1240:莫比乌斯函数
1240 莫比乌斯函数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使 ...
随机推荐
- 安装 ArcGISAPI31forSilverlight an i/o error occured while installing a file错误解决
安装ArcGISAPI31forSilverlight出现“an i/o error occured while installing a file……”主要是这个文件可能已经损坏了,如此,你在用到该 ...
- Android设置状态栏颜色
1.代码设置if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = this.getWindow ...
- 微信接口 output {"errMsg":"translateVoice:fail, the permission value is offline verifying"}
jsApiList : [ 'checkJsApi', 'startRecord', 'stopRecord','translateVoice','scanQRCode', 'openCard' ]增 ...
- Groovy的脚本统一于类的世界
http://groovy-lang.org/structure.html 3.2. Script class A script is always compiled into a class. Th ...
- 关于nexus的学习
1.首先下载 解压版: 2.将nexus的bin目录路径 写入 环境变量path中: 3.修改 nexus配置文件wrapper.conf 15行 ,指定java.exe文件位置(例如:wra ...
- win10编译caffe调用matlab接口
参考 https://www.cnblogs.com/njust-ycc/p/5776286.html https://www.cnblogs.com/heately/p/7922521.html
- (14)CountTriplets
一.问题描述 给定一个数组.三个索引 i,i ~ [0, array.length) j, j ~ [0, array.length) k, k ~ [0, array.length) 求有多少种组 ...
- MVC下 Area和Web同名的Controller问题
错误如下图: 解决方案: 1:Area下的XXXAreaRegistration 添加:new string[] { "xxx.Areas.xxx.Controllers" } 2 ...
- Linux之增加系统调用[内核编译]
声明:如需引用或者摘抄本博文源码或者其文章的,请在显著处注明,来源于本博文/作者,以示尊重劳动成果,助力开源精神.也欢迎大家一起探讨,交流,以共同进步- 0.0 由于操作系统实验的缘故,有一个实验需要 ...
- Git学习之连接GitHub远程仓库
在看此教程之前电脑上应该已安装好git,并且配置好基本信息,Git新手请从头开始. 第1步:创建SSH Key 在用户主目录下(Mac系统是在用户主目录下,可通过命令ll -a查看,Windows下自 ...