题意 假设a加上a全部数位上的数等于b时 a称为b的generator  求给定数的最小generator

给的数n是小于100,000的  考虑到全部数位和最大的数99,999的数位和也才45  因此我们仅仅须要从n-45到n枚举即可了

#include<cstdio>
#include<cstring>
using namespace std;
int t, n, a, b, ans, l;
int main()
{
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
ans = 0;
for (int i = n-50; i < n; ++i)
{
a = b = i;
while (b)
{
a += b % 10;
b /= 10;
}
if (a + b == n)
{
ans = i;
break;
}
}
printf ("%d\n", ans);
}
return 0;
}

For a positive integer N , the digit-sum of N is defined as the sum of N itself and its digits. When M is
the digitsum of N , we call N a generator of M .

For example, the digit-sum of 245 is 256 (= 245 + 2 + 4 + 5). Therefore, 245 is a generator of 256.

Not surprisingly, some numbers do not have any generators and some numbers have more than one generator. For example, the generators of 216 are 198 and 207.

You are to write a program to find the smallest generator of the given integer.

Input

Your program is to read from standard input. The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case takes one line
containing an integer N , 1N100,
000 .

Output

Your program is to write to standard output. Print exactly one line for each test case. The line is to contain a generator of N for each test case. If N has multiple generators,
print the smallest. If N does not have any generators, print 0.

The following shows sample input and output for three test cases.

Sample
Input

3
216
121
2005

Sample
Output

198
0
1979

UVa 1583 Digit Generator(数学)的更多相关文章

  1. UVa 1583 Digit Generator --- 水题+打表

    UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...

  2. UVa 1583 - Digit Generator

    A+A的每一位的数字的和=B 问你每一个B对应 的最小的A 是多少 不然输出0: #include <cstdio> #include <iostream> #include ...

  3. UVa 1583 - Digit Generator 解题报告 - C语言

    1.题目大意 如果a加上a的各个数字之和得到b,则说a是b的生成元.给出n其中$1\le n\le 100000$,求其最小生成元,若没有解则输出0. 2.思路 使用打表的方法打出各个数字a对应的b, ...

  4. uva 1583 Digit Generator(Uva-1583)

    题目不再写入了,vj:https://vjudge.net/problem/UVA-1583#author=0 主要讲的是找一个数的小于它的一个数,小于它的那个数每一位加起来再加上那个数就会等于原来的 ...

  5. UVa 1583 Digit Generator WA

    #include<stdio.h> int main() { long int n,i,s=0; while(scanf("%d",&n)!=EOF) { in ...

  6. UVa 1225 Digit Counting --- 水题

    UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...

  7. Digit Generator(水)

    题目链接:http://acm.tju.edu.cn/toj/showp2502.html2502.   Digit Generator Time Limit: 1.0 Seconds   Memor ...

  8. [C++]最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)

    Question 例题3-5 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583) 如果x+x的各个数字之和得到y,就是说x是y的生成元.给出n( ...

  9. 【UVA 1583】Digit Generator

    题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...

随机推荐

  1. UML_活动图

    一.活动图的组成元素 Activity Diagram Element 1.活动状态图(Activity) 2.动作状态(Actions) 3.动作状态约束(Action Constraints) 4 ...

  2. oracle 查询表名以及表的列名

    oracle 查询表名以及表的列名的代码.   1.查询表名: 代码如下: select table_name,tablespace_name,temporary from user_tables [ ...

  3. 【MSP是什么】MSP认证之项目管理与项目群管理的区别

    通常所说的项目管理是指运用各种相关知识.技能.方法与工具,为满足或超越项目有关各方对项目的要求与期望,所开展的各种计划.组织.领导.控制等方面的活动.具体包括项目范围管理.项目时间管理.项目成本管理. ...

  4. 【贪心】【Uva11729】 Commando War

    你有n个部下,每个部下需要完成一项任务.第i个部下需要你花Bi分钟交待任务,然后他会立刻独立地.无间断地执行Ji分钟后完成任务.你需要选择交待任务的顺序,使得所有任务尽早执行完毕(即最后一个执行完的任 ...

  5. Android服务端本地窗口FramebufferNativeWindow

    Android窗口系统 我们知道Android系统采用OpenGL来绘制3D图形,OpenGL ES提供了本地窗口(NativeWindow)的概念,无论是在Android平台中还是其他平台中,只要实 ...

  6. SqlServer判断数据库、表、存储过程、函数是否存在

    假设场景是: 需要给一个脚本给客户更新, 这个对象可能存在或不存在 -- 更新存储过程 USE [数据库名] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ...

  7. Unity IOC注入详细配置(MVC,WebApi)

    一直想写一篇关于unity 详细的配置信息的文章,也算是自我总结吧 先介绍了unity , Unity是微软官方推荐使用的轻型的IOC框架,支持各种方式的注入 ,使用来解耦的利器. 获取unity 的 ...

  8. 配置nginx静态资源路径

    1.修改nginx.conf文件 server节点下location节点的 root目录修改 location / { root html; index index.html index.htm; } ...

  9. 在controller间分享数据(第一种办法)

    Blood 血腥的方法 每个controller都有自己的scope, 同时也可以共享他们老爸的scope内的数据.如果我们想让两个controller共享数据的化, 有多种方法. 最直接血腥的就是在 ...

  10. oracle 集合定义

    集合:是具有相同定义的元素的聚合.Oracle有两种类型的集合: 可变长数组(VARRAY):可以有任意数量的元素,但必须预先定义限制值. 嵌套表:视为表中之表,可以有任意数量的元素,不需要预先定义限 ...