代码

#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. 【Atheros】Iperf性能测试的问题小结

    1. Iperf用文件作为数据源无效的问题 2. 在代码中修改iperf数据,iperf无法收到,但在mac层能拿到数据 3. TCP发不出去包的问题 1. Iperf用文件作为数据源无效的问题 Ip ...

  2. 将PHP 5.3.3 (cli)升级到PHP 5.6.31 (cli)

    centos默认系统安装的是php5.3 [root@sz-local1 scripts]# rpm -qa |grep phpphp-pdo-5.3.3-47.el6.x86_64php-mysql ...

  3. 【原创】Hibernate自动生成(2)

    本实战是博主初次学习Java,分析WCP源码时,学习HibernateTools部分的实战,由于初次接触,难免错误,仅供参考,希望批评指正. 开发环境: Eclipse Version: Photon ...

  4. Spring MVC 返回Json IE出现下载

    今天在做一个利用IFrame提交进行form提交表单的时候发现返回的json在ie下竟然弹出了下载的提示, 于是就查看了返回的Content-type:appliation/json;charset= ...

  5. 洛谷P1073 最优贸易==codevs1173 最优贸易

    P1073 最优贸易 题目描述 C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个 城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一 ...

  6. Sumdiv(较难数学题)

    Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20971   Accepted: 5290 Description Cons ...

  7. images have the “stationarity” property, which implies that features that are useful in one region are also likely to be useful for other regions.

    Convolutional networks may include local or global pooling layers[clarification needed], which combi ...

  8. redis持久化RDB详细操作步骤

    1.xshell远程登录服务器ssh root@192.168.142.130 2.切换到redis目录 3.创建一个配置文件s2-redis.conf 4.编辑文件 vi s2-redis.conf ...

  9. 记一次bash脚本报错原因

    准备部署上次写的 爬虫的定时任务,发现sh脚本 写为最简单的cd ,也报错 后来网上一波了解,原因竟是 : 额,格式问题,我为了图方便是在window里用notepad++写的,然后我再linux 系 ...

  10. QMessageBox简单使用

    首先要调用 #include <QMessageBox> 然后 QMessageBox msgBox; msgBox.setWindowTitle("错误"); msg ...