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 ...
随机推荐
- wifi 协议栈的历史的总结
google 了一下找到下面的网页关于wifi 协议栈的说明 https://www.lifewire.com/wireless-standards-802-11a-802-11b-g-n-and-8 ...
- protoc: error while loading shared libraries: libprotoc.so.9: cannot open shared object
使用protobuf出错:protoc: error while loading shared libraries: libprotoc.so.9: cannot open shared object ...
- LVS的体系结构
LVS集群的体系结构 章文嵩 (wensong@linux-vs.org) 转自LVS官方资料 2002 年 4 月 本文主要介绍了LVS集群的体系结构.先给出LVS集群的通用体系结构,并讨论了其的设 ...
- Android Weekly Notes Issue #241
Android Weekly Issue #241 January 22nd, 2017 Android Weekly Issue #241 本期内容包括: 经典导航模式Master/Detail的设 ...
- rc.local 开启自启动,检测是否成功
rc.local /etc/init.d/nginx start 查看运行状态 systemctl status rc-local ● rc-local.service - /etc/rc.local ...
- Python GIL、线程锁、信号量及事件
GIL是什么? GIL并不是Python的特性,它是在实现Python解析器(CPython)时所引入的一个概念.就好比C++是一套语言(语法)标准,但是可以用不同的编译器来编译成可执行代码.有名的编 ...
- 从Github上下载了项目,导入Android Studio,gradle 报错,应该怎么修改
一.从Github上获取源代码 我这里是直接下载ZIP文件 二.在本机的Android Studio上新建一个空白项目,目的主要是与刚从Github上下载的项目文件结构做对比 三.替换gradle文件 ...
- 1、VGG16 2、VGG19 3、ResNet50 4、Inception V3 5、Xception介绍——迁移学习
ResNet, AlexNet, VGG, Inception: 理解各种各样的CNN架构 本文翻译自ResNet, AlexNet, VGG, Inception: Understanding va ...
- Windows_Program_Via_C_Translate_Win32编程的背景知识/基础知识_包括基本输入输出机制介绍
Some Basic Background Story of The Win32 APIs Win32 API背景故事/背景知识 The Win32 application programming i ...
- fragment error
error: android.view.InflateException: Binary XML file line #6: Error inflating class fragment 解决办法 ...