bzoj 3462: DZY Loves Math II
3462: DZY Loves Math II
Time Limit: 20 Sec Memory Limit: 512 MB
Submit: 211 Solved: 103
[Submit][Status][Discuss]
Description

Input
第一行,两个正整数 S 和 q,q 表示询问数量。
接下来 q 行,每行一个正整数 n。
Output
输出共 q 行,分别为每个询问的答案。
Sample Input
9
29
1000000000000000000
Sample Output
9
450000036
HINT
感谢the Loser协助更正数据
对于100%的数据,2<=S<=2*10^6,1<=n<=10^18,1<=q<=10^5
/**************************************************************
Problem: 3462
User: JYYHH
Language: C++
Result: Accepted
Time:5736 ms
Memory:141916 kb
****************************************************************/ #include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
using namespace std;
const int ha=1000000007;
ll n;
int d[15],num=0,S,q,now;
int inv[20],f[2][maxn*9];
int zssum=0,ans; inline int add(int x,int y){
x+=y;
if(x>=ha) return x-ha;
else return x;
} inline void dp(){
f[0][0]=1;
now=0;
int pre=now,tp=S*num-zssum; for(int i=1;i<=num;i++){
now^=1; // memset(f[now],0,sizeof(f[now])); for(int j=0;j<d[i];j++){
int tot=0;
for(int u=j;u<=tp;u+=d[i]){
tot=add(tot,f[pre][u]);
if(u-j>=S) tot=add(tot,ha-f[pre][u-S]); f[now][u]=tot;
}
} pre=now;
}
} inline int C(ll x,int y){
int an=1;
for(int i=1;i<=y;i++) an=an*((ll)(x-i+1)%ha)%ha*(ll)inv[i]%ha;
return an;
} int main(){
inv[1]=1;
for(int i=2;i<=8;i++) inv[i]=-inv[ha%i]*(ll)(ha/i)%ha+ha; scanf("%d%d",&S,&q); int U=S;
for(int i=2;i*(ll)i<=U;i++) if(!(U%i)){
d[++num]=i,U/=i,zssum+=i;
if(!(U%i)){
while(q--) puts("0");
return 0;
}
}
if(U!=1) d[++num]=U,zssum+=U; dp(); while(q--){
ans=0; scanf("%lld",&n); if(n<zssum){
puts("0");
continue;
} n-=zssum; int tp=min((ll)num,n/S);
ll tt=n/S,lef=n-tt*S;
for(int i=0;i<=tp;i++) ans=add(ans,C(tt-i+num-1,num-1)*(ll)f[now][i*S+lef]%ha); printf("%d\n",ans);
} return 0;
}
bzoj 3462: DZY Loves Math II的更多相关文章
- BZOJ 3462 DZY Loves Math II ——动态规划 组合数
好题. 首先发现$p$是互质的数. 然后我们要求$\sum_{i=1}^{k} pi*xi=n$的方案数. 然后由于$p$不相同,可以而$S$比较小,都是$S$的质因数 可以考虑围绕$S$进行动态规划 ...
- ●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 3512: DZY Loves Math IV [杜教筛]
3512: DZY Loves Math IV 题意:求\(\sum_{i=1}^n \sum_{j=1}^m \varphi(ij)\),\(n \le 10^5, m \le 10^9\) n较小 ...
- bzoj 3309 DZY Loves Math 莫比乌斯反演
DZY Loves Math Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1303 Solved: 819[Submit][Status][Dis ...
- BZOJ 3569 DZY Loves Chinese II
Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上 ...
- bzoj 3560 DZY Loves Math V - 线性筛 - 扩展欧几里得算法
给定n个正整数a1,a2,…,an,求 的值(答案模10^9+7). Input 第一行一个正整数n. 接下来n行,每行一个正整数,分别为a1,a2,…,an. Output 仅一行答案. Sampl ...
- BZOJ 3569 DZY Loves Chinese II 树上差分+线性基
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3569 Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅 ...
随机推荐
- NGUI-Tweens
Tweens(补间动画) 补间动画有很多种: 这里以Tween Height为例: 项目层次: btn为一个按钮,group为一组图片精灵,预览图如下: 第一步:先为每个item附加一个Tween H ...
- crmsh语法
.查看配置信息 crm(live)# configure crm(live)configure# show node node1 node node2 property cib-bootstrap-o ...
- 普通用户操作tomcat项目时报:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program
在使用普通用户更新tomcat项目适合出现这个信息,Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At ...
- 软工实践Alpha冲刺(6/10)
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 已经解决登录注册等基本功能的界面. 完成了主界面的基本布局 ...
- js获取页面元素位置函数(跨浏览器)
function getElementPos(elementId) { var ua = navigator.userAgent.toLowerCase(); var isOpera = (ua.in ...
- vue cli & vue 3.x
vue cli & vue 3.x https://cli.vuejs.org/dev-guide/ui-api.html#ui-api https://cli.vuejs.org/zh/gu ...
- HDU - 3072 Intelligence System
题意: 给出一个N个节点的有向图.图中任意两点进行通信的代价为路径上的边权和.如果两个点能互相到达那么代价为0.问从点0开始向其余所有点通信的最小代价和.保证能向所有点通信. 题解: 求出所有的强连通 ...
- 【马克-to-win】学习笔记—— 第五章 异常Exception
第五章 异常Exception [学习笔记] [参考:JDK中文(类 Exception)] java.lang.Object java.lang.Throwable java.lang.Except ...
- Codeforces Round #328 (Div. 2) B
B. The Monster and the Squirrel time limit per test 1 second memory limit per test 256 megabytes inp ...
- 模拟Windows系统“回收站”
HTML: <!DOCTYPE html><html> <head> <meta http-equiv="content-type" co ...