代码

#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. Codeforces Round #392 (Div. 2) F. Geometrical Progression

    原题地址:http://codeforces.com/contest/758/problem/F F. Geometrical Progression time limit per test 4 se ...

  2. jquery 与javascript关系 ①取元素 ②操作内容 ③操作属性 ④操作 样式 ⑤ 事件 点击变色

    jQuery的min版本和原版功能是一样的,min版主要应用于已经开发成的网页中,而非min版 的文件比较大,里面有整洁的代码书写规范和注释,主要应用于脚本开发过程当中. JQuery是继protot ...

  3. lua例子(进出栈)

    #include <stdio.h> extern "C" { #include "lua-5.2.2/src/lauxlib.h" #includ ...

  4. Spring 和 filter

    标题是 spring和filter,但是这里却是说的spring MVC 项目中需要用到filter,filter中需要用到spring实例化的bean,于是为了简化就形成spring和filter了 ...

  5. pip源提示“not a trusted or secure host” 解决

    问题:The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored ...

  6. A/B测试与灰度发布

    1.A/B测试与灰度发布的理论 产品是多维度的,设计体验.交互体验.系统质量.运营支持等等, 测试的目的是为了系统最终的交付,一套各方面都足够好的系统,而不是文档上定义的系统,系统是需要不断进化的. ...

  7. python查询IP地址所属地

    1.linux命令行版 #!/usr/bin/python #-*- coding: utf-8 -*- import json import urllib import sys def get_da ...

  8. php生成条形码: barcodegen

    实例结构: 1. index.html <!DOCTYPE html> <html> <head> <title>Test with embedded ...

  9. PAT 1064. 朋友数(20)

    如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋友证号”.例如123和51就是朋友数,因为1+2+3 = 5+1 = 6,而6就是它们的朋友证号.给定一些整数,要求 ...

  10. centos7 使用postgres

    1: http://www.cnblogs.com/think8848/p/5877076.html 2:http://blog.csdn.net/xuaa/article/details/52262 ...