zoukankan      html  css  js  c++  java
  • 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就输出这个数。进行取余和取模运算。

  • 相关阅读:
    TensorFlow实战5——TensorFlow实现AlexNet
    TensorFlow实战4——TensorFlow实现Cifar10识别
    TensorFlow实战3——TensorFlow实现CNN
    基础定理推证
    中考几何汇总
    Onenote
    高中数学教材整理
    云盘
    12-27问题
    圆锥曲线(1)
  • 原文地址:https://www.cnblogs.com/yuanhang110/p/11229283.html
Copyright © 2011-2022 走看看