[Codeforces-div.1 55D] Beautiful numbers
[Codeforces-div.1 55D] Beautiful numbers

试题分析
还是离散化。。。\(f_{i,j,k}\)表示i位,gcd为j,余数为k。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define LL long long
inline LL read(){
LL x=0,f=1; char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const LL MAXN = 100010;
const LL INF = 2147483600;
LL sta[MAXN+1]={0,1,2,3,4,5,6,7,8,9,10,12,14,15,18,20,21,24,28,30,35,36,40,42,45,56,60,63,70,72,84,90,105,120,126,140,168,180,210,252,280,315,360,420,504,630,840,1260,2520},top;
inline LL gcd(LL a,LL b){
return (!b?a:gcd(b,a%b));
}
inline LL LCM(LL a,LL b){
if(!a||!b) return b|a;
return a*b/gcd(a,b);
}
LL f[21][50][2600];
LL cnt; LL str[MAXN+1],num[MAXN+1];
inline LL dfs(LL i,LL j,LL k,LL g){
if(i==0) return j&&(k%sta[j]==0);
if(!g && ~f[i][j][k]) return f[i][j][k];
LL ans=0; for(LL l=0;l<=(g?str[i]:9);l++){
LL x=LCM(sta[j],l);
ans+=dfs(i-1,num[x],(k*10%2520+l)%2520,g&(str[i]==l));
} return (g?ans:f[i][j][k]=ans);
}
inline LL init(LL x){
cnt=0; while(x) str[++cnt]=x%10,x/=10;
return dfs(cnt,0,0,1);
}
LL T;
int main(){
//freopen(".in","r",stdin);
memset(f,-1,sizeof(f));
T=read(); for(LL i=1;i<49;i++) num[sta[i]]=i;
while(T--){
LL L=read(),R=read(); LL ans=0;
ans+=init(R); ans-=init(L-1);
printf("%lld\n",ans);
}
return 0;
}
[Codeforces-div.1 55D] Beautiful numbers的更多相关文章
- CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...
- Codeforces 55D. Beautiful numbers(数位DP,离散化)
Codeforces 55D. Beautiful numbers 题意 求[L,R]区间内有多少个数满足:该数能被其每一位数字都整除(如12,24,15等). 思路 一开始以为是数位DP的水题,觉得 ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...
- CodeForces 55D Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- CodeForces - 55D Beautiful numbers —— 数位DP
题目链接:https://vjudge.net/problem/CodeForces-55D D. Beautiful numbers time limit per test 4 seconds me ...
- CodeForces - 55D - Beautiful numbers(数位DP,离散化)
链接: https://vjudge.net/problem/CodeForces-55D 题意: Volodya is an odd boy and his taste is strange as ...
- CF 55D - Beautiful numbers(数位DP)
题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...
- 【数位dp】CF 55D Beautiful numbers
题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...
随机推荐
- 【NOIP】提高组2012 同余方程
[算法]扩展欧几里德算法 [题解]学完扩欧就可以随便水了... 转化为不定方程ax-by=1. 因为1且题目保证有解,所以方程有唯一解. 紫书曰:同余方程的一个解其实指的是一个同余等价类. 所以满足x ...
- 表单元素(form、文本、按钮、选择)
表单元素 一.form form代表表单,功能:用于申明表单,定义采集数据的范围,也就是<form>和</form>里面包含的数据将被提交到服务器或者电子邮件里.<for ...
- Part2-HttpClient官方教程-Chapter4-HTTP 认证
原文链接地址 HttpClient 提供对由 HTTP 标准规范定义的认证模式的完全支持.HttpClient 的认证框架可以扩展支持非标准的认证模式,比如 NTLM 和 SPNEGO. 4.1 用户 ...
- 【1】记一次破解wifi
当然,使用的依旧是aircrack套件,这次依旧是跑字典,今天,捉到了另一个实验室icephone的wpa握手包,我猜测实验室的wifi一般都跟自己的名字有关,icephone刚好是8位字母,于是我就 ...
- python基础===open()文件处理使用介绍
本文转自:Python open()文件处理使用介绍 1. open()语法open(file[, mode[, buffering[, encoding[, errors[, newline[, c ...
- mysql 1366的错误 字符集错误解决方案
最近用mysqlalchmy的时候遇到了 sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1366, "Incorrec ...
- MySQL关键字大全
转载自:https://blog.csdn.net/benxiaohai888/article/details/77803090 在使用MySQL的时候,一般尽量避免用关键字作为表名,如使用关键字做表 ...
- mysql5.7 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql5.7初次登录使用提示 ERROR 1820 (HY000): You must reset your password using ALTER USER statement before ...
- HAProxy配置代理
1.代理需求 原始URL:https://www.xxx.com/mili_app/News/NewsServlet.do?processID=getNewsList&type=1&p ...
- 利用CSS3伪类做3D按钮
这是通过css3伪类实现的3d按钮,html代码为: <div id="container_buttons"> <p><a class="a ...