[BZOJ] DZY Loves Math 系列 I && II
为了让自己看起来有点事干 ,做个套题吧。。不然老是东翻翻西翻翻也不知道在干嘛。。。
\(\bf 3309: DZY \ Loves \ Math\)
令 \(h=f*\mu\)
很明显题目要求的就是$$\sum_{i=1}^{min(n,m)}h(i) \cdot \left \lfloor \frac{n}{i} \right \rfloor \left \lfloor \frac{m}{i} \right \rfloor$$
那个 \(*\) 就是狄利克雷卷积,虽然说我也不知道是不是这么写。。
然后我就不会了,这个卷出来又不是积性函数咋搞啊,暴力筛肯定T啊。。
然后通过奇奇妙妙的方法可以发现 \(h((p_1p_2 \cdots p_k)^t)=(-1)^k\),否则为 \(0\) 。大佬说随便分析一下就出来了,反正我是分析不出来,半懂不懂。。作为一个不负责任的博主当然就随便挂个链接。。
然后就阔以线性筛+前缀和预处理,询问分个块就完了。
#include<bits/stdc++.h>
#define LL long long
#define fr(i,x,y) for(int i=(x);i<=(y);i++)
#define rf(i,x,y) for(int i=(x);i>=(y);i--)
#define frl(i,x,y) for(int i=(x);i<(y);i++)
using namespace std;
const int N=10000001;
int b[N],p[N/10],L,c[N],a[N],h[N];
int T,n,m;
void read(int &x){
char ch=getchar();x=0;
for(;ch<'0'||ch>'9';ch=getchar());
for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
}
void init(){
//h[1]=1;
frl(i,2,N){
if (!b[i]) p[++L]=i,a[i]=i,c[i]=1,h[i]=1;
for(int j=1;i*p[j]<N;j++){
int x=i*p[j];
b[x]=1;
if (i%p[j]==0){
a[x]=a[i]*p[j];c[x]=c[i]+1;
if (i==a[i]) h[x]=1;
else h[x]=c[i/a[i]]==c[x]?-h[i/a[i]]:0;
break;
}
c[x]=1;a[x]=p[j];
h[x]=c[i]==1?-h[i]:0;
}
}
frl(i,2,N) h[i]+=h[i-1];
}
int main(){
init();
read(T);
while(T--){
read(n);read(m);
LL ans=0;
int pre=0;int p=1;
while(p<=n&&p<=m){
if (n/(n/p)<m/(m/p)) p=n/(n/p);
else p=m/(m/p);
ans+=1LL*(h[p]-h[pre])*(n/p)*(m/p);
pre=p;p++;
}
printf("%lld\n",ans);
}
return 0;
}
\(\bf 3309: DZY \ Loves \ Math \ II\)
别的部分都很好想,但是那个背包的部分简直神仙吧。。
我懒得写一遍题解,这篇题解让我最终看懂了QAQ
(你懒还有理了)
顺便,进本题第一页祭,合影留念QwQ
感觉啥也没优化啊??发生了啥???(也许是取模优化?不过我日常取模优化,只是因为感觉这样写更方便。。)
#include<bits/stdc++.h>
#define LL long long
#define fr(i,x,y) for(int i=(x);i<=(y);i++)
#define rf(i,x,y) for(int i=(x);i>=(y);i--)
#define frl(i,x,y) for(int i=(x);i<(y);i++)
using namespace std;
const int N=2000002;
const int p=1e9+7;
int S,q,m,ss;
LL n;
int d[10],L;
int f[N*7];
int inv;
void read(int &x){
char ch=getchar();x=0;
for(;ch<'0'||ch>'9';ch=getchar());
for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
}
void read(LL &x){
char ch=getchar();x=0;
for(;ch<'0'||ch>'9';ch=getchar());
for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
}
inline void Add(int &x,int y){
x+=y;
while(x<0) x+=p;
while(x>=p) x-=p;
}
int qpow(int a,int n){
LL ans=1;
for(LL sum=a;n;n>>=1,sum=sum*sum%p) if (n&1) ans=ans*sum%p;
return ans;
}
void init(){
int x=S;
for(int i=2;i*i<=x;i++)
if (x%i==0){
x/=i;d[++L]=i;ss+=i;
if (x%i==0){
fr(i,1,q) printf("0\n");
exit(0);
}
}
if (x>1) d[++L]=x,ss+=x;
m=S*L;
f[0]=1;
fr(i,1,L){
fr(j,d[i],m) Add(f[j],f[j-d[i]]);
rf(j,m,S) Add(f[j],-f[j-S]);
}
inv=1;frl(i,2,L) inv*=i;inv=qpow(inv,p-2);
}
inline int C(LL x){
LL ans=inv;
frl(i,0,L-1) ans=ans*((x-i)%p)%p;
//cout<<ans<<endl;
return ans;
}
int main(){
read(S);read(q);
init();
while(q--){
read(n);
if (n<ss){ printf("0\n");continue; }
n-=ss;
LL x=n/S;
int ans=0;
for(LL i=x;n-i*S<=m;i--)
Add(ans,1LL*C(i+L-1)*f[n-i*S]%p);
printf("%d\n",ans);
}
return 0;
}
/*
30 1
1000000000000000000
*/
[BZOJ] DZY Loves Math 系列 I && II的更多相关文章
- BZOJ DZY Loves Math系列
⑤(BZOJ 3560) $\Sigma_{i_1|a_1}\Sigma_{i_2|a_2}\Sigma_{i_3|a_3}\Sigma_{i_4|a_4}...\Sigma_{i_n|a_n}\ph ...
- DZY Loves Math 系列详细题解
BZOJ 3309: DZY Loves Math I 题意 \(f(n)\) 为 \(n\) 幂指数的最大值. \[ \sum_{i = 1}^{a} \sum_{j = 1}^{b} f(\gcd ...
- DZY Loves Math系列
link 好久没写数学题了,再这样下去吃枣药丸啊. 找一套应该还比较有意思的数学题来做. [bzoj3309]DZY Loves Math 简单推一下. \[\sum_{i=1}^n\sum_{j=1 ...
- bzoj DZY Loves Math V
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 509 Solved: 284[Submit][Status][Discuss] Descriptio ...
- bzoj 3462: DZY Loves Math II
3462: DZY Loves Math II Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 211 Solved: 103[Submit][Sta ...
- ●BZOJ 3309 DZY Loves Math
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3309 题解: 莫比乌斯反演,线筛 化一化式子: f(x)表示x的质因子分解中的最大幂指数 $ ...
- BZOJ 3561 DZY Loves Math VI
BZOJ 3561 DZY Loves Math VI 求\(\sum_{i=1}^{n}\sum_{j=1}^{m}\text{lcm}(i,j)^{\gcd(i,j)}\),钦定\(n\leq m ...
- BZOJ 3309: DZY Loves Math
3309: DZY Loves Math Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 761 Solved: 401[Submit][Status ...
- 【BZOJ】3309: DZY Loves Math 莫比乌斯反演优化
3309: DZY Loves Math Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007) ...
随机推荐
- Thread线程类
设置线程名 查看线程名是很简单的,调用Thread.currentThread().getName()即可. public class MyThreadDemo { public static voi ...
- Windows和Mac系统下安装Docker
在windows和mac系统中使用Docker Desktop安装Docker对系统的要求是很高的. 对于 Windows 系统来说,安装 Docker for Windows 需要符合以下条件: 必 ...
- Java基础学习笔记(六) - 数据结构和集合
一.认识数据结构 1.数据结构有什么用? 合理的使用数据结构,可以更方便的查找存储数据. 2.常见的数据结构 数据存储常用结构有:栈.队列.数组.链表和红黑树. 栈:堆栈(stack),它是运算受限的 ...
- 分享8点超级有用的Python编程建议
我们在用Python进行机器学习建模项目的时候,每个人都会有自己的一套项目文件管理的习惯,我自己也有一套方法,是自己曾经踩过的坑总结出来的,现在在这里分享一下给大家,希望多少有些地方可以给大家借鉴.
- 04-10 Bagging和随机森林
目录 Bagging算法和随机森林 一.Bagging算法和随机森林学习目标 二.Bagging算法原理回顾 三.Bagging算法流程 3.1 输入 3.2 输出 3.3 流程 四.随机森林详解 4 ...
- 09-01 Tensorflow1基本使用
目录 Tensorflow基本使用 一.确认安装Tensorflow 二.获取MNIST数据集 三.使用Tensorflow训练--Softmax回归 四.使用Tensorflow训练--卷积神经网络 ...
- 浅谈sqlserver的事务锁
锁的概述 一. 为什么要引入锁 多个用户同时对数据库的并发操作时会带来以下数据不一致的问题: 丢失更新 A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破坏了另一个修改的结果,比如订票系统 ...
- 解决 canvas 将图片转为base64报错: Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasEleme...
问题描述 当用户点击分享按钮时,生成一张海报,可以保存图片分享到朋友圈,用户的图片是存储在阿里云的OSS,当海报完成后,执行.canvas.toDataURL("image/png" ...
- Ubuntu分区方案
swap: 4G(跟你自己内存一样大):主分区:空间起始位置:用于交换空间 /boot: 300M(太小会导致软件无法升级):逻辑分区:空间起始位置:EXT4:/boot /: 30G:主分区:空间起 ...
- boost::VS2017下编译和配置boost库
环境: win10 vs2017 v141 1.下载 boost_1_70_0.zip. 2.以管理员方式打开 3. bootstrap.bat 4.编译64位库 b2.exe stage -- ...