码迷,mamicode.com
首页 > 其他好文 > 详细

1240 莫比乌斯函数

时间:2018-05-12 22:38:53      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:problem   math.h   image   http   alt   red   highlight   for   ane   

基准时间限制: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
/*
    data:2018.5.12
    author:gsw
    link:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1240
    account:2684524947@qq.com
*/
#define ll long long
#define IO ios::sync_with_stdio(false);

#include<math.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
int prime(int n)
{
    int m=sqrt(n)+1;
    int kk=0;
    for(int i=2;i<=m;i++)
    {
        if(n%i==0)
        {
            int cnt=0;
            while(n%i==0)
            {
                n=n/i;
                cnt++;
                if(cnt>=2)return 0;
            }
            kk++;
        }
    }
    if(n>1)kk++;
    if(kk%2==0)return 1;
    return -1;
}
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d\n",prime(n));
    //main();
    return 0;
}

  

1240 莫比乌斯函数

标签:problem   math.h   image   http   alt   red   highlight   for   ane   

原文地址:https://www.cnblogs.com/fantastic123/p/9029973.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!