首页 > 其他分享 >Fair Numbers CodeForces - 1465B

Fair Numbers CodeForces - 1465B

时间:2022-09-23 14:46:10浏览次数:43  
标签:10 好数 Fair LL CodeForces while 1465B Numbers

Fair Numbers CodeForces - 1465B

我们定义一个好数规则如下: 它能够整除自己的每一个非零位。
例如说,102 是一个好数,因为它能整除 1 和 2。282 则不是,因为它不能整除 8。
现在给定一个正整数 n,求大于等于 n 的最小好数。

Input

第一行为样例数t(1<=t<=1000),接下来t行包括一个n(1 <= n <= 1e18)

Output

输出t行,代表大于等于 n 的最小好数。

Sample Input

4
1
282
1234567890
1000000000000000000

Sample Output

1
288
1234568040
1000000000000000000

分析

直接从 n 开始枚举答案即可,其实我本来以为会超时的,毕竟 1e18的范围,但是没有超时,确实有一定的赌博成份在里面。
这个地方记录一下,我觉得需要证明一下这样不会超时。

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+10,INF=0x3f3f3f3f;
LL t,n;
bool chk(LL x) {
    LL m=0, temp=x, a[20];
    while(temp) {
        if(temp%10!=0) a[++m] = temp%10;
        temp/=10;
    }
    int i=1;
    while(i<=m) {
        if(n%a[i]!=0) break;
        i++;
    }
    return i==m+1;
}
int main() {
//    freopen("data.in", "r", stdin);
    cin>>t;
    while(t--) {
        cin>>n;
        while(1) { // TLE ?
            if(chk(n)) break;
            n++;
        }
        cout<<n<<endl;
    }
    return 0;
}

标签:10,好数,Fair,LL,CodeForces,while,1465B,Numbers
From: https://www.cnblogs.com/hellohebin/p/16722676.html

相关文章

  • LeetCode448. Find All Numbers Disappeared in an Array
    题意n个数,统计1-n中未出现的数方法遍历和标记代码classSolution{public:vector<int>findDisappearedNumbers(vector<int>&nums){sort(nums.beg......
  • FastCorrect&Fairseq学习笔记
    一工作说明:FastCorrect,字面意思就是快速纠错;这项主要是对asr的识别结果进行纠错,提升识别率;目前大部分的纠错模型采用了基于注意力机制的端到端自回归模型(seq2se......
  • CF1352A - Sum of Round Numbers
    CF1352A-SumofRoundNumbersA.SumofRoundNumbersApositive(strictlygreaterthanzero)integeriscalledroundifitisoftheformd00...0.Inotherw......
  • ABC264 G - String Fair
    DP+最短路+哈希G-StringFair(atcoder.jp)题意给若干个只包含小写字母的长度<=3的字符串\(T_i\),每个字符串有权值构造一个非空字符串S,若S中包含上述子串,则......
  • mt19937_64 get random numbers
    #include<ctime>#include<iostream>#include<random>usingnamespacestd;voiduInt32Array(intlen);intmain(intargs,char**argv){uInt32Array(a......
  • CF55D Beautiful numbers
    求\([l,r]\)中满足\(x\)能被\(x\)数位中所有非\(0\)位整除的数的个数。\(l,r\leq9\times10^{18}\)。\(lcm(1\sim9)=2520\)。标准的数位DP。用\(dp[i][j][k......
  • CF446C DZY Loves Fibonacci Numbers
    CF446CDZYLovesFibonacciNumbers题目大意在本题中,我们用\(f_i\)来表示第\(i\)个斐波那契数(\(f_1=f_2=1,f_i=f_{i-1}+f_{i-2}(i\ge3)\))。维护一个序列\(a\),长......
  • FairyGUI窗口拖动,关闭,加载图片
    1.在FairyGUI软件里面制作好窗口window的格式,按照官网上的来关闭按钮:closeButton、拖动范围:dragArea、步骤:1.新建一个空组件2.再建一个空组件命名为:frame3.frame组件......
  • 2. Add Two Numbers
    2.AddTwoNumbers题目Youaregiventwonon-emptylinkedlistsrepresentingtwonon-negativeintegers.Thedigitsarestoredinreverseorderandeachofthe......
  • PAT Advanced 1023 Have Fun with Numbers(20)
    题目描述:Noticethatthenumber123456789isa9-digitnumberconsistingexactlythenumbersfrom1to9,withnoduplication.Doubleitwewillobtain2469135......