[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) ...
随机推荐
- Docker 环境搭建(RedHat 7)
Docker 环境搭建(RedHat 7): CentOS7 下载 http://mirrors.sohu.com/centos/7/isos/x86_64/ 装载镜像文件 安装Linux 7, 参考 ...
- SpringCache - 请求级别缓存的简易实现
前言 在SpringCache缓存初探中我们研究了如何利用spring cache已有的几种实现快速地满足我们对于缓存的需求.这一次我们有了新的更个性化的需求,想在一个请求的生命周期里实现缓存. 需求 ...
- (八十四)c#Winform自定义控件-导航菜单(类Office菜单)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- HTML基础知识(块级标签,行内标签,行内块标签)
块级元素:独占一行,对宽高的属性值生效:如果不给宽度,块级元素就默认为浏览器的宽度,即就是100%宽: 行内元素:可以多个标签存在一行,对宽高属性值不生效,完全靠内容撑开宽高! 其中还有一种结合两种模 ...
- Kafka技术原理知识点总结
1.Kafka是由Linkedin公司开发的,使用Scala语言编写的,分布式,多副本,多分区的,发布订阅模式的消息系统,他通常用于日志系统的搭建,2.Kafka和Zookeeper:Kafka通过Z ...
- python编程基础之十四
列表的增加元素 l1 = [10, 20, 30] l1.append(40) # 末尾追加一个值为40的元素 l1.extend([50, 60]) # 末尾追加一系列元素,extend + 可 ...
- Vue-cli中axios传参的方式以及后端取的方式
0917自我总结 Vue-cli中axios传参的方式以及后端取的方式 一.传参 params是添加到url的请求字符串中的,用于get请求. data是添加到请求体(body)中的, 用于post请 ...
- fread优化读入
inline char nc() { static const int BS = 1 << 22; static unsigned char buf[BS],*st,*ed; if(st ...
- C++ Web框架::cintara
1.Cinatra是由C++开源社区purecpp发起的一个开源项目,是一个现代C++写的Web框架,旨在给用户提供一个易用.灵活和高性能的Web框架,让用户能完全专注于核心逻辑而无需关注http细节 ...
- 第三方软件 radmin提权
一款远控工具 端口扫描 4899 端口 上传 radmin.asp 木马读取 radmin的加密密文 下载radmin工具连接