E - Arithmetic Number
作者:互联网
特判\(X \geq 10^9\)的情况
剩下情况暴力枚举
#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL n;
int main() {
scanf("%lld", &n);
if (n >= 1e10) {
LL x = n, len = 0;
while (x) {len ++; x /= 10;}
for (int num = 0; num <= 9; num ++ ) {
LL ans = num;
for (int i = 1; i < len; i ++ )
ans = ans * 10 + num;
if (ans >= n) {
printf("%lld\n", ans);
return 0;
}
}
}
else if (n >= 1e9){
LL x = n, len = 0, res = 1e10;
if (9876543210 >= n) res = 9876543210;
while (x) {len ++; x /= 10;}
for (int num = 0; num <= 9; num ++ ) {
LL ans = num;
for (int i = 1; i < len; i ++ )
ans = ans * 10 + num;
if (ans >= n) {
res = min(ans, res);
printf("%lld\n", res);
return 0;
}
}
}
else {
LL x = n, len = 0, res = 1e10;
while (x) {len ++; x /= 10;}
for (int d = 0; d <= 9; d ++ ) {
for (int i = 0; i <= 9; i ++ ) {
LL num = i;
bool flag = 1;
for (int j = 2; j <= len; j ++ ) {
if (d * (j - 1) + i >= 10) {
flag = 0;
break;
}
num = num * 10 + (d * (j - 1) + i);
}
if (flag && num >= n) res = min(res, num);
}
for (int i = 9; i >= 0; i -- ) {
LL num = i;
bool flag = 1;
for (int j = 2; j <= len; j ++ ) {
if (i - d * (j - 1) < 0) {
flag = 0;
break;
}
num = num * 10 + (i - d * (j - 1));
}
if (flag && num >= n) res = min(res, num);
}
}
printf("%lld\n", res);
}
return 0;
}
标签:10,int,res,LL,Number,len,num,Arithmetic 来源: https://www.cnblogs.com/Angels-of-Death/p/15933876.html