ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和
链接 https://nanti.jisuanke.com/t/31456
参考题解 https://blog.csdn.net/ftx456789/article/details/82590044
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n");
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl;
using namespace std;
const int maxn=1e6+;
typedef long long ll;
map<ll,ll> ma,yin;
int check[maxn],prime[maxn],mu[maxn];
void Mobius(int N)//莫比乌斯函数线性筛
{
int pos=;mu[]=;
for (int i = ; i <= N ; i++)
{
if (!check[i])
prime[pos++] = i,mu[i]=-;
for (int j = ; j < pos && i*prime[j] <= N ; j++)
{
check[i*prime[j]] = ;
if (i % prime[j] == )
{
mu[i*prime[j]]=;
break;
}
mu[i*prime[j]]=-mu[i];
}
}
for(int i=;i<=N;i++)
mu[i]+=mu[i-];
}
ll sum(ll a)
{
if(a<=1e6)
return mu[a];
if(ma.count(a))
return ma[a];
ll temp=;
for(ll i=;i<=a;)
{
ll t=a/i;
ll k=a/t;
temp-=(k-i+)*sum(t);
i=k+;
}
return ma[a]=temp;
}
void shai(ll n)//筛素因子
{
ll x=n;
for(ll i=;i*i<=x;i++)
{
while(x%i==)
{
yin[i]++;
x/=i;
}
}
if(x>)yin[x]++;
}
ll solve(ll n,ll m)
{
if(m==)return ;//m等于0就是0喽
if(n==)return sum(m);//n等于1 就是莫比乌斯函数 u 的前 m 项和
for(auto it:yin)
{
if(n%it.fi==)
{
return solve(n,m/it.fi)-solve(n/it.fi,m);
}
}
}
int main()
{
Mobius(1e6);
ll n,m;
cin>>n>>m;
shai(m);
for(auto it:yin)
if(it.se>)
{
cout<<<<endl;
return ;
}
cout<<solve(m,n)<<endl;
return ;
}
ACM-ICPC 2018 徐州赛区网络预赛
ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和的更多相关文章
- 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 ...
- ACM-ICPC 2018 徐州赛区网络预赛(8/11)
ACM-ICPC 2018 徐州赛区网络预赛 A.Hard to prepare 枚举第一个选的,接下来的那个不能取前一个的取反 \(DP[i][0]\)表示选和第一个相同的 \(DP[i][1]\) ...
随机推荐
- SQL中的SELECT_简单查询语句总结
--以scott用户下的dept和emp表为例 --注意:如果scott用户不能使用,请使用system用户登录--解锁scott用户ALTER USER SCOTT ACCOUNT UNLOCK;- ...
- Understanding Scroll Views 深入理解 scroll view 读书笔记
Understanding Scroll Views 深入理解 scroll view 读书笔记 It may be hard to believe, but a UIScrollView is ...
- JSP 错误处理方法
web.xml中配置error-page标签 1.WEB工程中打开 web.xml 文件
- (转)编码剖析Spring管理Bean的原理
http://blog.csdn.net/yerenyuan_pku/article/details/52832434 在Spring的第一个案例中,我们已经知道了怎么将bean交给Spring容器进 ...
- maven打包的含义
我们在用maven构建java项目时,最常用的打包命令有mvn package.mvn install.deploy,这三个命令都可完成打jar包或war(当然也可以是其它形式的包)的功能,但这三个命 ...
- myBatis的binding错误:Invalid bound statement (not found)
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误这个问题我找了好久,终于找到了正确的写 ...
- BZOJ1232: [Usaco2008Nov]安慰奶牛cheer(最小生成树)
题意:给一个图 需要找到一个子图使得所有点都连通 然后再选择一个点做为起点 走到每个点并回到起点 每条边,每个点被经过一次就要花费一次边权.点权 题解:肯定是找一颗最小生成树嘛 然后惊奇的发现 任意选 ...
- koa源码解读
koa是有express原班人马打造的基于node.js的下一代web开发框架.koa 1.0使用generator实现异步,相比于回调简单和优雅和不少.koa团队并没有止步于koa 1.0, 随着n ...
- UVa-340-猜数字
#include <stdio.h> char ans[1000],gus[1000]; int num[10]; int main() { int n,cnt=1; while (sca ...
- 如何用纯 CSS 创作一种有削铁如泥感觉的菜单导航特效
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/XqYroe 可交互视频教 ...