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. java下的slf4j

    一.导读 我们使用log4j框架时,经常会用slf4j-api.在运行时,经常会遇到如下的错误提示: ? 1 2 3 4 5 SLF4J: Class path contains multiple S ...

  2. react admin

    react admin 管理后台的快速创建方式

  3. windows 环境变量%SystemDrive%和%SystemRoot%、%AppData%、%LocalAppData%、%TEMP% 等简写

    windows 环境变量%SystemDrive% 和%SystemRoot%.%AppData%.%LocalAppData%.%TEMP% 等简写 假设操作系统安装在 C: 盘 %SYSTEMRO ...

  4. 51Nod 1432 独木舟 (贪心)

    n个人,已知每个人体重.独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟? Input 第一行包含 ...

  5. PP: Shape and time distortion loss for training deep time series forecasting models

    Problem: time series forecasting Challenge: forecasting for non-stationary signals and multiple futu ...

  6. Oracle 12c中CDB与PDB实例参数更改影响实验

    基础知识单薄的同学,请逐字逐句阅读以下概念,来自于博客园AskScuti. 预备知识:什么是参数文件.存放位置.参数文件的分类和参数文件的命名方式.参数文件如何创建.参数文件加载顺序.参数分类.参数修 ...

  7. set的使用

    集合是Python的一种数据类型,集合是一个可变容器.常用于列表的去重. 什么是集合 集合是一个可变容器 集合中的数据对象都是唯一的(不可重复) 集合是无序的存储结构 集合是可迭代对象 集合内的元素是 ...

  8. Python-selenium,使用SenKey模块时所碰到的坑

    一.SenKey模块(模拟鼠标键盘操作) :python3中没有该模块,使用PyUserInput模块代替 二.PyUserInput模块安装前需要安装:pywin32和pyHook模块,pywin3 ...

  9. android 代码实现模拟用户点击、滑动等操作

    /** * 模拟用户点击 * * @param view 要触发操作的view * @param x 相对于要操作view的左上角x轴偏移量 * @param y 相对于要操作view的左上角y轴偏移 ...

  10. 白面系列 kafka

    kafka是一个分布式发布订阅消息系统,也可叫做MQ系统,MQ是Message Queue,消息队列. 通俗点,生产者往队列里写消息,消费者从队列里读.专业点,Producer通过TCP协议发送消息到 ...