Nearest Interesting Number
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的更多相关文章
- 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 ...
- Codeforces 1183A Nearest Interesting Number
题目链接:http://codeforces.com/problemset/problem/1183/A 题意:求不小于 a 且每位数和能被 4 整除的 最小 n 思路:暴力模拟就好. AC代码: # ...
- 算法笔记_093:蓝桥杯练习 Problem S4: Interesting Numbers 加强版(Java)
目录 1 问题描述 2 解决方案 1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its d ...
- 【转】JS中处理Number浮点数精度问题
https://github.com/dt-fe/number-precision ~(function(root, factory) { if (typeof define === "fu ...
- java实现 蓝桥杯 算法提高 Problem S4: Interesting Numbers 加强版
1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its digits consists of o ...
- Round in Oracle/VBA
VBA的 Round采用的是银行家算法(rounds to the nearest even number) Round(1.5) = 2 Round(0.5) = 在Oracle中实现银行家算法 S ...
- Wow! Such Sequence!(线段树4893)
Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- zoj 3673 1729
1729 Time Limit: 3 Seconds Memory Limit: 65536 KB 1729 is the natural number following 1728 and ...
- The shortest problem
The shortest problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
随机推荐
- 跳跃【BFS】
From 牛客网:https://ac.nowcoder.com/acm/problem/25160
- asp.net core 配置文件动态更新
IOptions<T> //站点启动后,获取到的值永远不变 IOptionsSnapshot<T> //站点启动后,每次获取到的值都是配置文件里的最新值 (reloadOnCh ...
- Java连载85-集合的Contains和Remove方法
一.包含与删除两种方法解析 1.boolean contains(Object o);判断集合中是否包含某个元素. package com.bjpowernode.java_learning; imp ...
- 844. 走迷宫(bfs模板)
给定一个n*m的二维整数数组,用来表示一个迷宫,数组中只包含0或1,其中0表示可以走的路,1表示不可通过的墙壁. 最初,有一个人位于左上角(1, 1)处,已知该人每次可以向上.下.左.右任意一个方向移 ...
- 实用沙盒工具 —— VMware Workstation15安装教程
一:简介 VMware Workstation(中文名"威睿工作站")是一款功能强大的桌面虚拟计算机软件,提供用户可在单一的桌面上同时运行不同的操作系统,和进行开发.测试 .部署新 ...
- nginx 简单理解和配置
1.概念 Nginx是一个高性能的HTTP和反向代理的web服务器,同时也提供了IMAP/POP3/SMTP服务,Nginx是由伊戈尔·塞索耶夫为俄罗斯访问量第二的Rambler.ru站点开发的,第一 ...
- sql 分组后查询出排序字段
select row_number() over(partition by CODE order by SEQUENCE) as RowIndex from Table 注:根据表的CODE 字 ...
- <软件工程基础>
我是JX_Z,学习信息安全方向 //(怎么在这头不头尾不尾的地方弄个自我介绍这么尴尬呢) 之前也写过一些随笔记录自己的学习过程 软件工程基础课程中遇到的问题和学习心得都会记录在这篇文章中不断更新. 谢 ...
- 火狐浏览器将网页保存为pdf
目录 火狐打印功能 火狐插件 save as pdf 深夜更博仙女镇 @ 有时候查一些技术博客之类的,当时收藏了,过一阵子再想查看的时候发现404了,所以稳妥的办法还是将把网页保存为pdf. 火狐打印 ...
- AcWing 1013. 机器分配
//分组背包 for物品 for体积 for 决策 #include <iostream> using namespace std; ; int n, m; int w[N][N]; in ...