AcWing 3547. 特殊数字
原题链接
简单
作者:
殇ベ_11
,
2021-05-23 08:24:44
,
所有人可见
,
阅读 264
题目描述
我们规定,对于一个整数 a,如果其各位数字相加之和能够被 4 整除,则称它是一个特殊数字。
现在,给定一个整数 n,请你计算并输出不小于 n 的最小特殊数字。
输入格式
一个整数 n。
输出格式
一个整数,表示不小于 n 的最小特殊数字。
数据范围
对于 30% 的数据,1≤n≤100。
对于 100% 的数据,1≤n≤1000。
样例
输入样例:
42
输出样例:
44
算法1
(暴力枚举) $O(n^2)$
C++ 代码
#include<cstdio>
#include<algorithm>
using namespace std;
int check(int x){
int a = 0;
int res = 0;
while(x)
{
a = x % 10;
x /= 10;
res += a;
}
//printf("%d \n",res);
if(res % 4 == 0) return true;
else return false;
}
int n;
int main(){
scanf("%d",&n);
for(int i = n;i <= n * 2; i ++){
if(check(i) == true) {
printf("%d",i);
return 0;
}
}
}