51nod 1240 莫比乌斯函数 【数论基础】
来源:互联网 发布:数据分析师加班厉害吗 编辑:程序博客网 时间:2024/06/07 04:06
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
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
int miu(int n){
int num=1;
for(int i=2;i*i<=n;i++){
if(n%i==0){
num++;
int cnt=0;
while(n%i==0){
n/=i;cnt++;
}
if(cnt>=2)return 0;
}
}
if(n==1) return 1;
return num%2==0?1:-1;
}
int main(){
int n;
cin>>n;
cout<<miu(n);
return 0;
}
0 0
- 51nod 1240 莫比乌斯函数 【数论基础】
- 51nod--1240莫比乌斯函数 (数论)
- 51nod 序列变换 [容斥原理+莫比乌斯函数]【数论+组合数学】
- 51nod点头网-1240 莫比乌斯函数
- 51nod 1240 莫比乌斯函数
- 51Nod-1240-莫比乌斯函数
- 51nod:1240 莫比乌斯函数
- 51nod-1240莫比乌斯函数
- 51nod 1240 莫比乌斯函数
- 莫比乌斯函数(51nod-1240)
- 51nod 1240 莫比乌斯函数
- 51nod 1240 莫比乌斯函数
- 51nod 1240 莫比乌斯函数
- 51nod 1240 莫比乌斯函数
- 51Nod 1240 莫比乌斯函数
- 51Nod 1240 莫比乌斯函数
- 51nod 1240 莫比乌斯函数
- 51Nod 1240:莫比乌斯函数
- HDU 2553 N皇后问题(dfs)
- 2017.05.13 有关c++中cin的学习
- 社招java面试记录
- Expected selector for Objective-C and Expected method body
- html5第八课时,结构伪类选择器
- 51nod 1240 莫比乌斯函数 【数论基础】
- Sublime text 3快捷键
- 不容易系列之(3)—— LELE的RPG难题
- 丽娃河的狼人传说
- 程序运行时 线程
- CFileDialog、CColorDialog、CFontDialog三个类的使用说明
- html5第八课时,状态伪类选择器
- STL 中栈和队列的使用方法
- java内存特点