CodeForces 55D Beautiful numbers (数位DP+状态简化,5级)

J - Beautiful numbers
Crawling in process... Crawling failed Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Appoint description:

Description

Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by each of its nonzero digits. We will not argue with this and just count the quantity of beautiful numbers in given ranges.

Input

The first line of the input contains the number of cases t (1 ≤ t ≤ 10). Each of the next t lines contains two natural numbers li and ri (1 ≤ li ≤ ri ≤ 9 · 1018).

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d).

Output

Output should contain t numbers — answers to the queries, one number per line — quantities of beautiful numbers in given intervals (from li to ri, inclusively).

Sample Input

Input
1
1 9
Output
9
Input
1
12 15
Output
2

思路:很容易能想到三维DP dp[第几位][模上最小公倍数数的余数][最小公倍数]

          最小公倍数到2520 为止 ,故 需要 19x2520x2520 爆空间了。

         但实际上能取到的最小公倍数没有2520个,只要几十个,因此可以哈希一下,因为DP只要记录其不同状态就可以了。

        dp不需要每个数都算原因是不同数的mod数不同。因此不会错

         接下来,就是水数位DP了。

     

#include<iostream>
#include<cstring>
#include<cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define clr(f,z) memset(f,z,sizeof(f))
typedef long long LL;
using namespace std;
LL dp[22][2521][50];
const int MOD=2520;
int bit[22];
int gcd(int a,int b)
{ int z;
  while(b)
  {
    z=b;b=a%b;a=z;
  }
  return a;
}
int LCM(int a,int b)
{
  return a*b/gcd(a,b);
}
int to[2521];
void data()
{ int pos=0;
  FOR(i,1,2520)
  if(MOD%i==0)//有可能是因子的,离散做状态
  {
    to[i]=pos++;
  }
}
LL DP(int pp,int mod,int lcm,bool big)
{
  if(pp==0)return mod%lcm==0;
  if(big&&dp[pp][mod][to[lcm]]!=-1)return dp[pp][mod][ to[lcm] ];
  int kn=big?9:bit[pp];
  LL ret=0;
  FOR(i,0,kn)
  { int zlcm;
    if(i==0)zlcm=lcm;
    else zlcm=LCM(lcm,i);
    ret+=DP(pp-1,(mod*10+i)%MOD,zlcm,big||kn!=i);
  }
  if(big)dp[pp][mod][to[lcm]]=ret;
  return ret;
}
LL get(LL x)
{
  int pos=0;
  while(x)
  {
    bit[++pos]=x%10;
    x/=10;
  }
  return DP(pos,0,1,0);
}
int main()
{
  LL x,y;data();clr(dp,-1);
  int n;
  cin>>n;
  while(n--)
  { cin>>x>>y;
    cout<<get(y)-get(x-1)<<"\n";
  }
}



当前提供的引用内容并未提及关于Codeforces比赛M1的具体时间安排[^1]。然而,通常情况下,Codeforces的比赛时间会在其官方网站上提前公布,并提供基于不同时区的转换工具以便参赛者了解具体开赛时刻。 对于Codeforces上的赛事而言,如果一场名为M1的比赛被计划举行,则它的原始时间一般按照UTC(协调世界时)设定。为了得知该场比赛在UTC+8时区的确切开始时间,可以遵循以下逻辑: - 前往Codeforces官网并定位至对应比赛页面。 - 查看比赛所标注的标准UTC起始时间。 - 将此标准时间加上8小时来获取对应的北京时间(即UTC+8)。 由于目前缺乏具体的官方公告链接或者确切日期作为依据,无法直接给出Codeforces M1比赛于UTC+8下的实际发生时段。建议定期访问Codeforces平台查看最新动态更新以及确认最终版程表信息。 ```python from datetime import timedelta, datetime def convert_utc_to_bj(utc_time_str): utc_format = "%Y-%m-%dT%H:%M:%SZ" bj_offset = timedelta(hours=8) try: # 解析UTC时间为datetime对象 utc_datetime = datetime.strptime(utc_time_str, utc_format) # 转换为北京时区时间 beijing_time = utc_datetime + bj_offset return beijing_time.strftime("%Y-%m-%d %H:%M:%S") except ValueError as e: return f"错误:{e}" # 示例输入假设某场Codeforces比赛定于特定UTC时间 example_utc_start = "2024-12-05T17:35:00Z" converted_time = convert_utc_to_bj(example_utc_start) print(f"Codeforces比赛在北京时间下将是:{converted_time}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值