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 ...
随机推荐
- TTimer源码研究
TTimerProc = procedure of object; IFMXTimerService = interface(IInterface) ['{856E938B-FF7B-4E13-85D ...
- java读取properties文件中参数值
在类文件中加入代码: //config.properties.sysInfo //sysInfo.properties在文件夹的路径为/src/config/properties/sysInfo.pr ...
- (转)CentOS6.5安装Darwin Streaming Server搭建RTSP流媒体服务器
参考: 1,CentOS6.5安装Darwin Streaming Server搭建RTSP流媒体服务器 http://www.yimiju.com/articles/567.html
- Machine Learning in Action(6) AdaBoost算法
Adaboost也是一种原理简单,但很实用的有监督机器学习算法,它是daptive boosting的简称.说到boosting算法,就不得提一提bagging算法,他们两个都是把一些弱分类器组合起来 ...
- AutoItLibrary安装和常见问题解决
http://blog.csdn.net/bible_reader/article/details/52044345
- javase练习题--每天写写
package com.javaTestDemo; import java.util.Scanner; public class JavaTest1 { public static void main ...
- 用php描述顺序查找
//顺序查找(数组里查找某个元素) $arr = array(3,55,45,2,67,76,6.7,-65,85,4); function seq_sch($array, $k){ for($i=0 ...
- Understand JavaScript Callback Functions and Use Them
In JavaScript, functions are first-class objects; that is, functions are of the type Object and they ...
- Java标准输入
Java: import java.util.*; public class Main{ public static void main(String args[]){ Scanner cin = n ...
- 「LOJ#10015」「一本通 1.2 练习 2」扩散(并查集
题目描述 一个点每过一个单位时间就会向 444 个方向扩散一个距离,如图所示:两个点 a .b 连通,记作 e(a,b),当且仅当 a .b的扩散区域有公共部分.连通块的定义是块内的任意两个点 u.v ...