A - Beautiful numbers
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector> using namespace std; #define LL long long
const int MOD = ;
LL dp[][][];
int a[];
int Hash[]; LL gcd(LL a, LL b)
{
return b?gcd(b,a%b):a;
} LL dfs(int pos, int num, int lcm, bool limit)
{
if(-==pos) return num%lcm == ;
if(!limit && ~dp[pos][Hash[lcm]][num]) return dp[pos][Hash[lcm]][num];
LL ans = ;
int end = limit?a[pos]:;
for(int i=; i<=end; i++)
ans += dfs(pos-, (num*+i)%MOD, i?lcm*i/gcd(lcm,i):lcm, limit&&i==a[pos]);
if(!limit) dp[pos][Hash[lcm]][num] = ans;
return ans;
} LL solve(LL n)
{
int pos = ;
while(n)
{
a[pos++] = n%;
n /= ;
}
return dfs(pos-, , , );
} int main()
{
int T;
scanf("%d", &T);
int cnt = ;
for(int i=; i<=MOD; i++)
if(MOD%i == )
Hash[i] = cnt++;
memset(dp, -, sizeof(dp));
while(T--)
{
long long l, r;
scanf("%lld%lld", &l, &r);
printf("%lld\n", solve(r)-solve(l-));
}
return ;
}
A - Beautiful numbers的更多相关文章
- CodeForces 55D Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- 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 Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- CF 55D - Beautiful numbers(数位DP)
题意: 如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers.求区间 [a,b] 中 Beautiful numbers 的个数. 分析:先分析出,2~9 的最大的最小公 ...
- Codeforces Beta Round #51 D. Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- Beautiful Numbers(牛客网)
链接:https://ac.nowcoder.com/acm/problem/17385来源:牛客网 题目描述 NIBGNAUK is an odd boy and his taste is stra ...
- CodeForces 55D "Beautiful numbers"(数位DP+离散化处理)
传送门 参考资料: [1]:CodeForces 55D Beautiful numbers(数位dp&&离散化) 我的理解: 起初,我先定义一个三维数组 dp[ i ][ j ][ ...
- 【数位dp】Beautiful Numbers @2018acm上海大都会赛J
目录 Beautiful Numbers PROBLEM 题目描述 输入描述: 输出描述: 输入 输出 MEANING SOLUTION CODE Beautiful Numbers PROBLEM ...
随机推荐
- wireshark 学习 2
使用wireshark抓到的wifi数据包如果是加密的,就只能显示密文,无法得到真正的数据. 如果知道AP和SSID和key,就可以解密wifi数据包,显示上层协议的数据. 在wireshark中设置 ...
- Whats the difference between service tomcat ./startup.sh and ./catalina.sh run
stack overflow 给出的答案: catalina.sh run starts tomcat in the foreground, displaying the logs on the co ...
- Ubuntu Linux系统环境变量配置文件【转】
本文转载自:https://my.oschina.net/qinlinwang/blog/30471 Ubuntu Linux系统环境变量配置文件: /etc/profile : 在登录时,操作系统 ...
- Linux:普通用户不能执行ifconfig命令问题
有客户现场服务器禁用了root帐号,在普通帐号下,执行ifconfig,提示bash:ifconfig command not found: 导致业务系统无法用普通帐号获取ifcnofig的MAC地址 ...
- Windows内存性能分析(一)内存泄漏
判断内存性能表现主要是为了解决如下两个问题: 1. 当前web应用是否存在内存泄漏,如果有,问题的程度有多大? 2. 如果web应用的代码无法进一步改进,当前web应用所在的服务器是否存在内存上的瓶颈 ...
- 利用Trigger完成WPF 的动画-渐显
其实渐显很简单,就是改变控件的透明度. WPF提供了Trigger这个东西. 下面是动画代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 <Style x:Key=&quo ...
- Linux档案属性
输入命令:ls -al 档案类型权限: 第一個字元代表这个档案是『目录.档案或链接档等等』: 当为[ d ]则是目录: 当为[ - ]则是目录: 若是[ l ]则表示为链接档(link file): ...
- html5 WebWorkers 防止浏览器假死
在Web开发的时候经常会遇到浏览器不响应事件进入假死状态,甚至弹出“脚本运行时间过长“的提示框,如果出现这种情况说明你的脚本已经失控了. 一个浏览器至少存在三个线程:js引擎线程(处理js).GUI渲 ...
- JavaScript-Tool:jquery.md5.js
ylbtech-JavaScript-Tool:jquery.md5.js 1.返回顶部 1. 引入js后 使用方法:document.write($.md5('1234')); 加密结果:81dc9 ...
- vue 使用scss报错
vue-cli默认没有scss-loader,需要安装依赖:sass-loader node-sass 安装之后重启就可以使用: <style lang="scss"> ...