代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 20000000;
bool check[N+20];
int prime[N+20], mu[N+20], tot;
void mobius() {
memset(check, 0, sizeof(check));
mu[1] = 1; tot = 0;
for(int i = 2; i <= N; ++i) {
if(!check[i]) {
prime[tot++] = i;
mu[i] = -1;
}
for(int j = 0; j < tot; ++j) {
if(i * prime[j] > N) break;
check[i * prime[j]] = true;
if(i % prime[j] == 0) {
mu[i * prime[j]] = 0; break;
}else {
mu[i * prime[j]] = -mu[i];
}
}
}
for(int i = 2; i <= N; ++i) mu[i] += mu[i-1];
}
ll factor[50]; int f_cnt = 0, f_exp[50];
void get_factor(ll x) {
f_cnt = 0; ll n = x;
for(int i = 0; i < tot; ++i) {
if(1LL * prime[i] * prime[i] > n) break;
if(x % prime[i] == 0) {
f_exp[f_cnt] = 0;
while(x % prime[i] == 0) {
x /= prime[i]; f_exp[f_cnt]++;
}
factor[f_cnt++] = prime[i];
}
}
if(x > 1) {
f_exp[f_cnt] = 1; factor[f_cnt++] = x;
}
}
map<ll, int> mp;
ll mertens(ll x) {
if(x < N) return mu[x];
if(mp.count(x)) return mp[x];
ll ret = 0;
for(ll i = 2, last; i <= x; i = last+1) {
last = x/(x/i);
ret += (last - i + 1)*mertens(x/i);
}
return mp[x] = 1-ret;
}
ll S(ll n, ll m, ll min_p) {
if(m == 0) return 0;
if(n == 1) return mertens(m);
ll p = factor[min_p];
//cout << n << " " << m << " " << p << endl;
return -S(n/p,m,min_p+1)+S(n,m/p,min_p);
}
ll m, n;
int main() {
mobius();
cin >> m >> n;
get_factor(n);
for(int i = 0; i < f_cnt; ++i) {
if(f_exp[i] > 1) {
puts("0"); return 0;
}
}
cout << S(n, m, 0) << endl;
return 0;
}

【ACM-ICPC 2018 徐州赛区网络预赛】D.Easy Math 杜教筛的更多相关文章

  1. [ACM-ICPC 2018 徐州赛区网络预赛][D. Easy Math]

    题目链接:Easy Math 题目大意:给定\(n(1\leqslant n\leqslant 10^{12}),m(1\leqslant m\leqslant 2*10^{9})\),求\(\sum ...

  2. 徐州赛区网络预赛 D Easy Math

    比赛快结束的适合看了一下D题,发现跟前几天刚刚做过的HDU 5728 PowMod几乎一模一样,当时特兴奋,结果一直到比赛结束都一直WA.回来仔细一琢磨才发现,PowMod这道题保证了n不含平方因子, ...

  3. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  4. ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

    ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...

  5. 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)

    H.Ryuji doesn't want to study 27.34% 1000ms 262144K   Ryuji is not a good student, and he doesn't wa ...

  6. ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)

    传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE

    In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study

    262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track

    262144K   Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...

  10. ACM-ICPC 2018 徐州赛区网络预赛 I. Characters with Hash

    Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encryp ...

随机推荐

  1. 解决ajax跨域问题的多种方法

    //第一种方法使用jsonp的方式 <script type="text/javascript" src="http://www.youxiaju.com/js/j ...

  2. ORA-24408: could not generate unique server group name

    一台新虚拟机,CentOS 6.5系统,用lnmp一键安装包安装好Nginx + PHP环境,再安装Oracle客户端,准备搭建PHP连接Oracle,访问oracle.php,测试连接Oracle的 ...

  3. redis-windows和linux下安装

    Window 下安装 下载地址:https://github.com/dmajkic/redis/downloads. 下载到的Redis支持32bit和64bit.根据自己实际情况选择,将64bit ...

  4. Surpassing Human-Level Face Verification Performance on LFW with GaussianFace

    Face verification remains a challenging problem in very complex conditions with large variations suc ...

  5. js跨浏览器复制: ZeroClipboard

    实例结构: demo.html <script type="text/javascript" src='http://code.jquery.com/jquery.js'&g ...

  6. less (css预处理)

    用法 1. 必须在head内 2. 样式文件必须先加载 <head> <meta charset='utf-8'> <link rel="stylesheet/ ...

  7. java对IO的操作

    import java.io.*; public class HelloWorld { //Main method. public static void main(String[] args) { ...

  8. ElasticSearch(二十一)正排和倒排索引

    1.区别 搜索的时候,要依靠倒排索引:排序的时候,需要依靠正排索引,看到每个document的每个field,然后进行排序,所谓的正排索引,其实就是doc values 在建立索引的时候,一方面会建立 ...

  9. header函数使用

    header('HTTP/1.1 200 OK'); //设置一个404头: header('HTTP/1.1 404 Not Found'); //设置地址被永久的重定向 header('HTTP/ ...

  10. Java注释Override、Deprecated、SuppressWarnings

    在J2SE5.0的java.lang包中预定义了三个注释:Override.Deprecated和SuppressWarnings Override 这个注释的作用是标识某一个方法是否覆盖了它的父类的 ...