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. jvm gc 调优 实战

    非常不错的文章们 转自: 中文:http://blog.csdn.net/dragonassassin/article/details/51010947 http://josh-persistence ...

  2. jQuery---弹幕效果

    弹幕效果 <!doctype html> <html> <head> <meta charset="utf-8"> <titl ...

  3. 针对wordpress CMS的信息收集

    如果发现一个站点用的是wordpress管理系统的话, 可以试试默认的后台地址:/wp-admin/ 访问后自动跳转置 后台登录界面 用户名收集 :/?author=1 依次访问/author=1 , ...

  4. Spring Boot整合Freemarker

    一.首先导入依赖 <!-- 添加freemarker模版的依赖 --> <dependency>     <groupId>org.springframework. ...

  5. PP: Triple-shapelet networks for time series classification

    Problem: time series classification shapelet-based method: two issues 1. for multi-class imbalanced ...

  6. Vue中v-show和v-if的使用以及区别

    个人博客 地址:http://www.wenhaofan.com/article/20190321143330 v-if 1.v-if 根据条件渲染,它会确保在切换过程中条件块内的组件销毁和重建    ...

  7. redis五大数据类型以及常用操作命令

    Redis的五大数据类型 String(字符串) string是redis最基本的类型,你可以理解成与Memcached一模一样的类型,一个key对应一个value.string类型是二进制安全的.意 ...

  8. 初识消息队列--ActiveMq

    消息队列 即MessageQueue,是一种消息中间件,在遇到系统请求量比较大的情况下,导致请求堆积过多无法及时返回,可以通过它进行异步的消息处理,从而缓解系统压力. ActiveMq ActiveM ...

  9. OpenCV: “vector”: 未声明的标识符和Vector不是模板

    漏写using namespace std: 会出现此错误“vector”: 未声明的标识符或者是将“vector”写成‘Vector’会出现Vector不是模板的错误:改正即可

  10. SequoiaDB 巨杉数据库Docker镜像使用教程

    为方便用户快速体验,SequoiaDB 巨杉数据库提供基于 Docker 的镜像.本文介绍如何在 Docker 环境下部署 SequoiaDB 分布式集群环境.   集群规划 我们准备在五个容器中部署 ...