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 ...
随机推荐
- PAT (Advanced Level) Practice 1005 Spell It Right (20 分) (switch)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...
- Sass和Scss
Sass:https://www.sass.hk/ Sass是什么 Sass 是一款强化 CSS 的辅助工具,它在 CSS 语法的基础上增加了变量 (variables).嵌套 (nested rul ...
- elasticsearch 5.5 query 过程 源码分析
(1)请求 transfer to 任意node 节点 标记为coordinate node server入口函数 transportSearchAction doExecute方法 coordin ...
- python requests [Errno 104] Connection reset by peer
有个需求,数据库有个表有将近 几千条 url 记录,每条记录都是一个图片,我需要请求他们拿到每个图片存到本地.一开始我是这么写的(伪代码): import requests for url in ur ...
- Oracle 12c中CDB与PDB实例参数更改影响实验
基础知识单薄的同学,请逐字逐句阅读以下概念,来自于博客园AskScuti. 预备知识:什么是参数文件.存放位置.参数文件的分类和参数文件的命名方式.参数文件如何创建.参数文件加载顺序.参数分类.参数修 ...
- Docker最全教程——从理论到实战(十四)
本篇教程主要讲解基于容器服务搭建TeamCity服务,并且完成内部项目的CI流程配置.教程中也分享了一个简单的CI.CD流程,仅作探讨.不过由于篇幅有限,完整的DevOps,我们后续独立探讨. 为了降 ...
- HTML-表格-基础表格
主要内容: HTML表格 基本语法和结构: 案例: border用在table标签里面,表示边框的. th标签是加粗,width是宽度,表格宽度用在table里面.: caption用在table ...
- 爬虫 urllib
内置http请求库 模块 urllib.request 请求模块 urllib.error 异常处理模块 urllib.parse url解析模块 urllib.robotparser ...
- importing-cleaning-data-in-r-case-studies
目录 importing-cleaning-data-in-r-case-studies 导入数据 查看数据结构 下面的一些都是查数据结构的 separate 拆分单元格 读取指定位置的数据 stri ...
- jupyter快捷键使用
1. 服务启动与停止 环境为windows10系统 ctrl+R输入cmd,输入命令jupyter notebook启动 使用Control-c停止服务 2.常用快捷键 模式切换 当前cell侧边为蓝 ...