CodeForces55D

本文介绍了一种算法,用于计算特定范围内能被其所有非零数字整除的整数数量。通过使用动态规划和数学方法,文章详细展示了如何高效地解决这个问题。

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).

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

用每个数除以数位的LCM
但是会发现每个数%2520就可以存状态了
2520是1到9的LCM

坑点 0算一个

#include<iostream>
#include<cmath>
#include<queue>
#include<stack>
#include<memory.h>
#include<algorithm>
using namespace std;
long long shi[21];
long long dp[21][7000][100];
long long mp[9000000];
int gcd(int a, int b)
{
    if (b == 0) return a;
    return gcd(b, a%b);
}
long long lcm(long long q, long long w)
{
    return q*w / gcd(q, w);
}
long long bte[30];
long long qw = 0;
long long dfs(long long weishu, long long biaoji, long long benshen, long long quanti)
{
    if (!mp[quanti])mp[quanti] = ++qw;
    if (weishu == 0)
    {
    //  if (qiandao == 0)return 0;
        if (benshen%quanti)return 0;
        return 1;
    }
    if (biaoji&&dp[weishu][benshen][mp[quanti]] != -1)return dp[weishu][benshen][mp[quanti]];
    long long da = 0;
    long long bianjie = biaoji ? 9 : bte[weishu];
    for (int a = 0;a <= bianjie;a++)
    {
        int xyb = benshen * 10 + a;
        xyb %= 2520;
        int xyq = quanti;
        if (a)xyq = lcm(quanti, a);
        da += dfs(weishu - 1, biaoji || a < bianjie,xyb, xyq);
    }
    if (biaoji)dp[weishu][benshen][mp[quanti]] = da;
    return da;
}
long long jiejue(long long q)
{
    if (q == 0)return 1;
    if (q < 0)return 0;
    //if (q < 10)return q;
    long long y = q;
    bte[0] = 0;
    while (y)
    {
        bte[++bte[0]] = y % 10;
        y /= 10;
    }
    return dfs(bte[0], 0, 0, 1);
}
int main()
{
#define int long long
    int T;
    cin >> T;
    shi[0] = 1;
    memset(dp, -1, sizeof(dp));
    for (int a = 1;a <= 20;a++)shi[a] = shi[a - 1] * 10;
    while (T--)
    {
        int n, m;
        cin >> n >> m;
        int yuy = jiejue(m) - jiejue(n - 1);
        cout << yuy << endl;
    }
    return 0;
}
### Codeforces 1487D Problem Solution The problem described involves determining the maximum amount of a product that can be created from given quantities of ingredients under an idealized production process. For this specific case on Codeforces with problem number 1487D, while direct details about this exact question are not provided here, similar problems often involve resource allocation or limiting reagent type calculations. For instance, when faced with such constraints-based questions where multiple resources contribute to producing one unit of output but at different ratios, finding the bottleneck becomes crucial. In another context related to crafting items using various materials, it was determined that the formula `min(a[0],a[1],a[2]/2,a[3]/7,a[4]/4)` could represent how these limits interact[^1]. However, applying this directly without knowing specifics like what each array element represents in relation to the actual requirements for creating "philosophical stones" as mentioned would require adjustments based upon the precise conditions outlined within 1487D itself. To solve or discuss solutions effectively regarding Codeforces' challenge numbered 1487D: - Carefully read through all aspects presented by the contest organizers. - Identify which ingredient or component acts as the primary constraint towards achieving full capacity utilization. - Implement logic reflecting those relationships accurately; typically involving loops, conditionals, and possibly dynamic programming depending on complexity level required beyond simple minimum value determination across adjusted inputs. ```cpp #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<long long> a(n); for(int i=0;i<n;++i){ cin>>a[i]; } // Assuming indices correspond appropriately per problem statement's ratio requirement cout << min({a[0], a[1], a[2]/2LL, a[3]/7LL, a[4]/4LL}) << endl; } ``` --related questions-- 1. How does identifying bottlenecks help optimize algorithms solving constrained optimization problems? 2. What strategies should contestants adopt when translating mathematical formulas into code during competitive coding events? 3. Can you explain why understanding input-output relations is critical before implementing any algorithmic approach? 4. In what ways do prefix-suffix-middle frameworks enhance model training efficiency outside of just tokenization improvements? 5. Why might adjusting sample proportions specifically benefit models designed for tasks requiring both strong linguistic comprehension alongside logical reasoning skills?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值