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

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

Analysis:

Even if we will iterate over all possible numbers starting from aa and check if sum of digits of the current number is divisible by 44, we will find the answer very fast. The maximum possible number of iterations is no more than 55.

Codes:

My previous codes:

 #include<bits/stdc++.h>
using namespace std;
int f(int n)
{
int s=0;
while(n){
s+=n%10;
n=n/10;
}
return s;
}
int main()
{
int n;
while(cin>>n)
{
for(int i=n;i<=1000;i++) //运行老是无以通过!
{
if(f(i)%4==0) break;
}
cout<<f(i)<<endl;
}
return 0;
}

By learning:

 #include<bits/stdc++.h>
using namespace std;
int sum(int n){
int s=0;
while(n){
s+=n%10;
n/=10;
}
return s;
} int main(){
int n;
while(cin>>n){
while(sum(n)%4!=0){
n++; //很简洁优美的一定情况下的自增哦!
}
cout<<n<<endl;
}
}

Nearest Interesting Number的更多相关文章

  1. 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 i ...

  2. Codeforces 1183A Nearest Interesting Number

    题目链接:http://codeforces.com/problemset/problem/1183/A 题意:求不小于 a 且每位数和能被 4 整除的 最小 n 思路:暴力模拟就好. AC代码: # ...

  3. 算法笔记_093:蓝桥杯练习 Problem S4: Interesting Numbers 加强版(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its d ...

  4. 【转】JS中处理Number浮点数精度问题

    https://github.com/dt-fe/number-precision ~(function(root, factory) { if (typeof define === "fu ...

  5. java实现 蓝桥杯 算法提高 Problem S4: Interesting Numbers 加强版

    1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its digits consists of o ...

  6. Round in Oracle/VBA

    VBA的 Round采用的是银行家算法(rounds to the nearest even number) Round(1.5) = 2 Round(0.5) = 在Oracle中实现银行家算法 S ...

  7. Wow! Such Sequence!(线段树4893)

    Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...

  8. zoj 3673 1729

    1729 Time Limit: 3 Seconds      Memory Limit: 65536 KB 1729 is the natural number following 1728 and ...

  9. The shortest problem

    The shortest problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...

随机推荐

  1. git Auto packing the repository in background for optimum performance

    遇到问题: git本地仓库,如果长时间不进行清理,几个月以后的某一天,可能拉取代码的时候突然提示你 git Auto packing the repository in background for ...

  2. arcgis10.2下载安装教程

    ArcGIS Desktop 10.2 完全安装教程(含win7 32/64位+下载地址+亲测可用) 时间: 2014年08月20日   阅读: 622,262   分类: GIS探秘   标签: A ...

  3. 暂停后保存sql server profiler的跟踪结果

  4. ArcMap 导出Table数据到Excel

  5. 关于IO板的输出(Do的写入)

    IO板的输入输出遵循MODBUS协议 1.单个DO开关量寄存器写入-功能码05 例子-打开信道3 01 05 00 02 00 00 CD CA 01 从机地址(由io的配置文件决定) 05  功能码 ...

  6. php 字符串常用函数

    数组.字符串和数据库是我们函数里面最.最.最常用的三类函数. 当然PHP的字符串函数也有很多.我们最常使用的两个系列的字符串: 1.单字节字符串处理函数 2.多字节字符串处理函数 3.字符串编码转换函 ...

  7. 03_TypeScript函数

    1.函数的定义 es5定义函数的方法 //函数声明法 function run(){ return 'run'; } //函数表达式 var run = function(){ return 'run ...

  8. Java8之Stream详解

    Java8中提供了Stream对集合操作作出了极大的简化,学习了Stream之后,我们以后不用使用for循环就能对集合作出很好的操作.   一.流的初始化与转换   Java中的Stream的所有操作 ...

  9. prach 839滤波系数

  10. SQL Server 疑难杂症--转换科学计数法的数值字符串为decimal类型

    今天在操作数据库时,需要将字符串转换成Decimal类型.代码如下: select cast('0.12' as decimal(18,2)); select convert(decimal(18,2 ...