【ACM-ICPC 2018 徐州赛区网络预赛】D.Easy Math 杜教筛
代码
#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 杜教筛的更多相关文章
- [ACM-ICPC 2018 徐州赛区网络预赛][D. Easy Math]
题目链接:Easy Math 题目大意:给定\(n(1\leqslant n\leqslant 10^{12}),m(1\leqslant m\leqslant 2*10^{9})\),求\(\sum ...
- 徐州赛区网络预赛 D Easy Math
比赛快结束的适合看了一下D题,发现跟前几天刚刚做过的HDU 5728 PowMod几乎一模一样,当时特兴奋,结果一直到比赛结束都一直WA.回来仔细一琢磨才发现,PowMod这道题保证了n不含平方因子, ...
- ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)
ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...
- ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)
ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...
- 计蒜客 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 ...
- ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)
传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...
- 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 ...
- 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 ...
- ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track
262144K Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...
- 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 ...
随机推荐
- xmlUtil 解析 创建
http://yangzi09150915.blog.163.com/blog/static/32953487201072911410398/ package com.aibi.cmdc.webSer ...
- java getResourcesAsStream()如何获取WEB-INF下的文件流
getResourcesAsStream()来读取.properties文件,但是getResourcesAsStream()仅在java项目时能获取根目录的文件: 在web项目中,getResour ...
- Java泛型的应用
一.泛型类 package generics; /** * 泛型类,格式:public class 类名<泛型类型1, ...> * @author zhongfg * @date 201 ...
- 【BZOJ4894】天赋 有向图生成树计数
[BZOJ4894]天赋 Description 小明有许多潜在的天赋,他希望学习这些天赋来变得更强.正如许多游戏中一样,小明也有n种潜在的天赋,但有一些天赋必须是要有前置天赋才能够学习得到的.也就是 ...
- go语言之接口一
在Go语言中,一个类只需要实现了接口要求的所有函数,我们就说这个类实现了该接口 我们定义了一个File类,并实现有Read().Write().Seek().Close()等方法.设 想我们有如下接口 ...
- Tensorflow 初级教程(一)
初步介绍 Google 于2011年推出人工深度学习系统——DistBelief.通过DistBelief,Google能够扫描数据中心数以千计的核心,并建立更大的神经网络.Google 的这个系统将 ...
- ABAP动态生成经典应用之Dynamic SQL Excute 程序
[转自http://blog.csdn.net/mysingle/article/details/678598]开发说明:在SAP的系统维护过程中,有时我们需要修改一些Table中的数据,可是很多Ta ...
- Springmvc注解启用
http://www.blogbus.com/wanping-logs/235898637.html 使用注解的原因 最方便的还是启用注解 注解方便,而且项目中很流行. 配置文件尽量减少,主要使用 ...
- 网络的分层协议总结(转发:https://www.cnblogs.com/Zhang-wj/p/5907534.html)
网络的分层协议总结 OSI七层模型OSI 中的层 功能 TCP/IP ...
- 每天一个Linux命令(26)chown命令
chown命令改变某个文件或目录的所有者和所属的组,该命令可以向某个用户授权,使该用户变成指定文件的所有者或者改变文件所属的组. (1)用法: 用法: chown [选项 ...