1815: easy problem

http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1815

数字并不需要从1开始枚举;最大的每位和不到60;

1815: easy problem

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 145  Solved: 68

Submit Status Web Board

Description

给你一个数字N,N的范围是1~1000000,求一个最小的正整数M,这个数字M的各个位的数字加上它本身之和恰好为N。当然,如果没有解,输出0。

Input

输入数据由多组数据组成,每行由一个数字N组成(1<=N<=1000000)。

Output

对于每组数据,输出仅一行包含一个整数M。如果对于每个N,存在最小的M,则输出这个最小值。如果不存在这个最小的M,则输出0。

Sample Input

216 121 2005

Sample Output

19801979
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
const int SIZE=1e6+10;
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        for(int x=max(n-60,1);x<n;x++){
            int tmp=x,sum=x;
            while(tmp){
                sum+=tmp%10;
                tmp/=10;
            }
            if(sum==n){ans=x;break;}
        }
        printf("%d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值