CF 55D - Beautiful numbers(数位DP)
题意:
如果一个数能被自己各个位的数字整除,那么它就叫 Beautiful numbers。
求区间 [a,b] 中 Beautiful numbers 的个数。
分析:先分析出,2~9 的最大的最小公倍数是 2520({5,7,8,9}),先预处理出所有可能的最小公倍数m[c]
dp[i][d][c]表示长度i, 余数d,各位上的数的最小公倍数是m[c]的个数。
- #include<cstdio>
- #include<cstring>
- #define mod 2520
- ll dp[][][];
- int bit[],m[],mnum;
- int gcd(int a,int b){
- int tmp;
- while(a%b){
- tmp=b;
- b=a%b;
- a=tmp;
- }
- return b;
- }
- int lcm(int a,int b){
- return a*b/gcd(a,b);
- }
//查最小公倍数的标号- int tfind(int x){
- int ll=,rr=mnum;
- while(ll<=rr){
- int mid=(ll+rr)>>;
- if(m[mid]<x)ll=mid+;
- else rr=mid-;
- }
- return ll;
- }
- void init(){
- memset(dp,-,sizeof(dp));
- mnum=;
- for(int i=;i<=mod;++i)
- if(mod%i==)
- m[++mnum]=i;
- }
- ll dfs(int i,int d,int c,int e){
- if(i==)return d%m[c]?:;
- if(!e&&dp[i][d][c]!=-)return dp[i][d][c];
- int l=e?bit[i]:;
- ll num=;
- for(int j=;j<=l;++j)
- {
- int td=(d*+j)%mod;
- int tc=c;
- if(j)tc=tfind(lcm(m[c],j));
- num+=dfs(i-,td,tc,e&&(j==l));
- }
- return e?num:dp[i][d][c]=num;
- }
- ll solve(ll x){
- int len=;
- while(x){
- bit[++len]=x%;
- x/=;
- }
- return dfs(len,,,);
- }
- int main()
- {
- int t;
- scanf("%d",&t);
- init();
- ll x,y;
- while(t--){
- scanf("%I64d%I64d",&x,&y);
- printf("%I64d\n",solve(y)-solve(x-));
- }
- return ;
- }
CF 55D - Beautiful numbers(数位DP)的更多相关文章
- CF 55D. Beautiful numbers(数位DP)
题目链接 这题,没想出来,根本没想到用最小公倍数来更新,一直想状态压缩,不过余数什么的根本存不下,看的von学长的blog,比着写了写,就是模版改改,不过状态转移构造不出,怎么着,都做不出来. #in ...
- codeforces 55D - Beautiful numbers(数位DP+离散化)
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 题意: Volodya is an odd boy and his taste is strange as ...
- 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+数论)
题意:求[L,R](1<=L<=R<=9e18)区间中所有能被自己数位上的非零数整除的数的个数 分析:丛数据量可以分析出是用数位dp求解,区间个数可以转化为sum(R)-sum(L- ...
- codeforces 55D. Beautiful numbers 数位dp
题目链接 一个数, 他的所有位上的数都可以被这个数整除, 求出范围内满足条件的数的个数. dp[i][j][k], i表示第i位, j表示前几位的lcm是几, k表示这个数mod2520, 2520是 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 【数位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 ...
- 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 ...
随机推荐
- 【BZOJ2049】 [Sdoi2008]Cave 洞穴勘测
Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别编号为1到n)以及若干通道组成,并且每条通道连接了恰好 ...
- Create CSS3 Buttons Compatible with All Browsers
Create CSS3 Buttons Compatible with All Browsers http://www.ourtuts.com/create-css3-buttons-compatib ...
- 1020: [SHOI2008]安全的航线flight - BZOJ
Description在设计航线的时候,安全是一个很重要的问题.首先,最重要的是应采取一切措施确保飞行不会发生任何事故,但同时也需要做好最坏的打算,一旦事故发生,就要确保乘客有尽量高的生还几率.当飞机 ...
- winform访问url传参有返回值
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net;usi ...
- 【莫比乌斯反演】关于Mobius反演与gcd的一些关系与问题简化(bzoj 2301 Problem b&&bzoj 2820 YY的GCD&&BZOJ 3529 数表)
首先我们来看一道题 BZOJ 2301 Problem b Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd( ...
- [转载]Eziriz .NET Reactor 4.7.0.0 官方原版+破解补丁(强大的代码保护和软件防盗版工具)
Eziriz .NET Reactor 是一个强大的代码保护和软件防盗版工具,完全由.NET框架编写..NET Reactor支持NET平台的软件许可系统,并支持NET程序集所有语言.当.Net编译器 ...
- C++ DLL 模板 .
C++ DLL 模板 1.使用VS2005创建Win32 DLL项目,选择空项目,然后加入CppDll.h和CppDll.cpp文件. 2.修改CppDll.h和CppDll.cpp文件使之成为需要的 ...
- 发现一个可以在线运行JS代码的网站
平时可以在这里玩 http://jsbin.com/
- js jquery学习
1.js api http://api.vfreesoft.com/ 2.26个jquery小技巧 http://www.cnblogs.com/shouce/p/5084565.html 3. ...
- sqlserver查询指定树形结构的所有子节点
用标准sql的with实现递归查询(sql2005以上肯定支持,sql2000不清楚是否支持): with subqry(id,name,pid) as ( select id,name,pid fr ...