[bzoj2296][POJ Challenge]随机种子【构造】

【题目链接】
  https://www.lydsy.com/JudgeOnline/problem.php?id=2296
【题解】
  前十位用来保证 1 10 出现过,后 6 位用来保证这个数是 x 的倍数。由于 x < 1 e 6 所以一定有解。
  时间复杂度 O ( 1 )
【代码】

/* - - - - - - - - - - - - - - -
    User :      VanishD
    problem :   [bzoj2269]
    Points :    O(1)
- - - - - - - - - - - - - - - */
# include <bits/stdc++.h>
# define    ll      long long
# define    inf     0x3f3f3f3f
using namespace std;
int read(){
    int tmp = 0, fh = 1; char ch = getchar();
    while (ch < '0' || ch > '9'){ if (ch == '-') fh = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9'){ tmp = tmp * 10 + ch - '0'; ch = getchar(); }
    return tmp * fh;
}
int main(){
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    ll lim = 9876543210000000ll, les;
    for (int opt = read(); opt > 0; opt--){
        int tmp = read();
        if (tmp == 0){
            printf("%lld\n", -1ll);
            continue;
        }
        les = lim % tmp;
        if (les == 0) les = tmp;
        printf("%lld\n", lim + (tmp - les));
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/d_vanisher/article/details/80738069