51 Nod 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<iostream>
#include<string.h>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
int n,prime,m,cnt;
bool flag;
while(~scanf("%d",&n)){
flag=0;
prime=0;
m=sqrt(n);//减小复杂度
for(int i=2;i<=m;i++)
{
if(n%i==0){
cnt=0;
prime++;//i为一个质因子
while(n%i==0){
n/=i;
cnt++;
}
if(cnt>1){//代表有平方因子
flag=1;
break;
}
}
}
if(flag)
printf("0\n");
else{
if(n!=1)//可以确定定剩下的n值为1或者大于m的质数
prime++;
prime%2==0?printf("1\n"):printf("-1\n");
}
}
return 0;
}
51 Nod 1240 莫比乌斯函数的更多相关文章
- 51 Nod 1244 莫比乌斯函数前n项和
积性函数前n项和必看好文 https://blog.csdn.net/skywalkert/article/details/50500009 递归计算的时候要用map记忆化一下,前面的打表会比较快一点 ...
- 51 NOD 1244 莫比乌斯函数之和(杜教筛)
1244 莫比乌斯函数之和 基准时间限制:3 秒 空间限制:131072 KB 分值: 320 难度:7级算法题 收藏 关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens) ...
- 51nod 1240 莫比乌斯函数
题目链接:51nod 1240 莫比乌斯函数 莫比乌斯函数学习参考博客:http://www.cnblogs.com/Milkor/p/4464515.html #include<cstdio& ...
- 51nod 1240 莫比乌斯函数【数论+莫比乌斯函数】
1240 莫比乌斯函数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用 ...
- 51Nod 1240:莫比乌斯函数
1240 莫比乌斯函数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使 ...
- 51nod--1240莫比乌斯函数 (数论)
题目: 1240 莫比乌斯函数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先 ...
- 51 NOD 1239 欧拉函数之和(杜教筛)
1239 欧拉函数之和 基准时间限制:3 秒 空间限制:131072 KB 分值: 320 难度:7级算法题 收藏 关注 对正整数n,欧拉函数是小于或等于n的数中与n互质的数的数目.此函数以其首名研究 ...
- 51 nod 1188 最大公约数之和 V2
1188 最大公约数之和 V2 题目来源: UVA 基准时间限制:2 秒 空间限制:262144 KB 分值: 160 难度:6级算法题 给出一个数N,输出小于等于N的所有数,两两之间的最大公约数 ...
- Relatively Prime Powers CodeForces - 1036F (莫比乌斯函数容斥)
Relatively Prime Powers CodeForces - 1036F Consider some positive integer xx. Its prime factorizatio ...
随机推荐
- Simple scatter method in 2d picture(Qt)
Result: grayMap: MathTools: // // Created by Administrator on 2017/8/17. // #ifndef QTSCATTER_MATHTO ...
- 【leetcode】657. Robot Return to Origin
Algorithm [leetcode]657. Robot Return to Origin https://leetcode.com/problems/robot-return-to-origin ...
- Python3-IO模型
IO模型 IO模型介绍 阻塞IO(blocking IO) 非阻塞IO(non-blocking IO) 多路复用IO(IO multiplexing) 异步IO(Asynchronous I/O) ...
- 即速应用_微信小程序开发 http://www.jisuapp.cn/
即速应用_微信小程序开发 http://www.jisuapp.cn/
- python3.7 contextvars在asyncio使用的
from contextvars import ContextVar import asyncio import random cv = ContextVar('cv') async def wait ...
- input[type=file]上传文件(格式判断、文件大小、上传成功后操作)
var isUploadImg = false; //在input file内容改变的时候触发事件******************上传图片 $('#filed').change(function( ...
- ffmpeg h264 encdoer 速度对比
h264_qsv frame= 250 fps=0.0 q=-0.0 Lsize= 1401kB time=00:00:10.00 bitrate=1146.8kbits/s speed= 14x l ...
- 005_tcp/ip监控
system.monitor.tcpstat 一.listen+established+time wait+close wait. listen:SELECT mean("listen&qu ...
- 开启gtid导入报错
导入报错 [root@redis02 data]# mysql -u root -p < ht.sqlEnter password: ERROR 1840 (HY000) at line 24: ...
- Vue -- 数据监听
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...