Codeforces1183A(A题)Nearest Interesting Number

Polycarp knows that if the sum of the digits of a number is divisible by 3, then the number itself is divisible by 3. He assumes that the numbers, the sum of the digits of which is divisible by 4, are also somewhat interesting. Thus, he considers a positive integer n interesting if its sum of digits is divisible by 4.

Help Polycarp find the nearest larger or equal interesting number for the given number a. That is, find the interesting number nn such that n≥a and n is minimal.

Input

The only line in the input contains an integer (1a1000).

Output

Print the nearest greater or equal interesting number for the given number aa. In other words, print the interesting number nn such that n≥a and n is minimal.

 

 1 #include<iostream>
 2 using namespace std;
 3 int main() {
 4     int a,n,sum=0,i;
 5     cin>>a;
 6     for(i=a; i<=1005; i++) {
 7         int b=i;
 8         while(b) {
 9             int t=b%10;
10             b=b/10;
11             sum+=t;    
12         }
13         if(sum%4==0) {
14             cout<<i;
15             i=1006;
16         }
17         sum=0;
18     }
19 }

思路分析:输入一个数a,将它从a递增来获得它的最小的各位数和能整出4的整数。先求个十百千位数之和,如果和能整除4就输出这个数。进行取余和取模运算。

 

转载于:https://www.cnblogs.com/yuanhang110/p/11229283.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值