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

AC代码

直接暴力查找n的因子情况就行了

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
inline int check(int n)
{
int k=2;
int res=0;
while(k*k<=n)
{
int _=0;
if(n%k==0)
{
res++;
while(n%k==0)
{
n/=k;
_++;
}
if(_>1)
return 0;
}
k++;
}
if(res&1)
return 1;
else
return -1;
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int n;
cin>>n;
if(n==1)
{
cout<<1<<endl;
return 0;
}
cout<<check(n)<<endl;
return 0;
}

51Nod 1240:莫比乌斯函数的更多相关文章

  1. 51nod 1240 莫比乌斯函数

    题目链接:51nod 1240 莫比乌斯函数 莫比乌斯函数学习参考博客:http://www.cnblogs.com/Milkor/p/4464515.html #include<cstdio& ...

  2. 51nod 1240 莫比乌斯函数【数论+莫比乌斯函数】

    1240 莫比乌斯函数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用 ...

  3. 51nod 1244 莫比乌斯函数之和

    题目链接:51nod 1244 莫比乌斯函数之和 题解参考syh学长的博客:http://www.cnblogs.com/AOQNRMGYXLMV/p/4932537.html %%% 关于这一类求积 ...

  4. 51 Nod 1240 莫比乌斯函数

    1240 莫比乌斯函数  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使 ...

  5. 51nod 1244 莫比乌斯函数之和 【杜教筛】

    51nod 1244 莫比乌斯函数之和 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号.具体定义如下: 如果一个数包含 ...

  6. [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== ...

  7. 51nod 1244 莫比乌斯函数之和(杜教筛)

    [题目链接] http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 [题目大意] 计算莫比乌斯函数的区段和 [题解] 利 ...

  8. 51Nod.1244.莫比乌斯函数之和(杜教筛)

    题目链接 map: //杜教筛 #include<map> #include<cstdio> typedef long long LL; const int N=5e6; in ...

  9. 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) \ ...

随机推荐

  1. 把旧系统迁移到.Net Core 2.0 日记 (16) --Cors跨域访问

    IE浏览器的Intranet局域网设置默认是可以跨域访问的.chrome就不可以. 这里说的跨域是指javascript代码不能跨域, 当然你在后端controller代码里用HttpClient.G ...

  2. 谈一谈JUnit神奇的报错 java.lang.Exception:No tests found matching

    最近在学习Spring+SpringMVC+MyBatis,一个人的挖掘过程确实有点艰难,尤其是有一些神奇的报错让你会很蛋疼.特别是接触一些框架还是最新版本的时候,会因为版本问题出现很多错误,欢迎大家 ...

  3. Notation, First Definitions 转 http://brnt.eu/phd/node9.html

    LaTeX command Equivalent to Output style Remarks \textnormal{...} {\normalfont...} document font fam ...

  4. pycharm模板

    使用pycharm的模板 File - Settings (ctrl+alt+s) Editor - File and Code Templates - Python Script 可以使用部分变量. ...

  5. Linux学习 : Socket 网络编程入门

    一.socket()函数 int socket(int domain, int type, int protocol); domain:即协议域,又称为协议族(family).常用的协议族有,AF_I ...

  6. 3.5 C++间接继承

    参考:http://www.weixueyuan.net/view/6362.html 总结: 假设类C继承自类B,类B继承自类A.那么类C中的除了能够继承B类的成员函数和成员变量外,同样也能继承B类 ...

  7. 使用MyEclipse开发Java EE应用:用XDoclet创建EJB 2 Session Bean项目(三)

    MyEclipse限时秒杀!活动火热开启中>> [MyEclipse最新版下载] 三.配置XDoclet支持的项目 默认情况下,MyEclipse EJB项目未配置使用XDoclet功能. ...

  8. jdbc中Class.forName(driverName)的作用

    上次面试别人问我jdbc的过程: 我是这样回答的: Class.forName加载驱动 DriverManager.connect(url,username, password)获取连接对象 conn ...

  9. 使用keytool生成公钥、私钥、证书并且读取出来,使用私钥签名jar并验证(转)

    参考链接:http://happyqing.iteye.com/blog/2139504 :https://blog.csdn.net/arjelarxfc/article/details/52461 ...

  10. <Using ZooKeeper><Deploy & Use>

    安装与部署 配置过程相当简单.集群模式部署: wget http://www-us.apache.org/dist/zookeeper/stable/zookeeper-3.4.10.tar.gz t ...