UVa 1583 Digit Generator(数学)
题意 假设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 , 1N
100,
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(数学)的更多相关文章
- UVa 1583 Digit Generator --- 水题+打表
UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...
- UVa 1583 - Digit Generator
A+A的每一位的数字的和=B 问你每一个B对应 的最小的A 是多少 不然输出0: #include <cstdio> #include <iostream> #include ...
- UVa 1583 - Digit Generator 解题报告 - C语言
1.题目大意 如果a加上a的各个数字之和得到b,则说a是b的生成元.给出n其中$1\le n\le 100000$,求其最小生成元,若没有解则输出0. 2.思路 使用打表的方法打出各个数字a对应的b, ...
- uva 1583 Digit Generator(Uva-1583)
题目不再写入了,vj:https://vjudge.net/problem/UVA-1583#author=0 主要讲的是找一个数的小于它的一个数,小于它的那个数每一位加起来再加上那个数就会等于原来的 ...
- UVa 1583 Digit Generator WA
#include<stdio.h> int main() { long int n,i,s=0; while(scanf("%d",&n)!=EOF) { in ...
- UVa 1225 Digit Counting --- 水题
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...
- Digit Generator(水)
题目链接:http://acm.tju.edu.cn/toj/showp2502.html2502. Digit Generator Time Limit: 1.0 Seconds Memor ...
- [C++]最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)
Question 例题3-5 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583) 如果x+x的各个数字之和得到y,就是说x是y的生成元.给出n( ...
- 【UVA 1583】Digit Generator
题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...
随机推荐
- Xshell不能连接SSH的解决
异常处理汇总-服 务 器 http://www.cnblogs.com/dunitian/p/4522983.html 重新启动看看:/etc/init.d/ssh restart (/etc/ini ...
- PHP 表单验证 - 验证 E-mail 和 URL
----------------------------------------------------------------------------- 本节展示如何验证名字.电邮和 URL. -- ...
- Error Correct System(模拟)
Error Correct System Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- B. Sereja and Mirroring
B. Sereja and Mirroring time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Zero Downtime Upgrade of Oracle 10g to Oracle 11g Using GoldenGate — 2
Prepare 10g Database for OGG Create GGS and GGS_MON Database Users SQL> create tablespace ggs_tbs ...
- C# 封装-属性
属性使封装更容易 可以使用属性(properties),这些方法对其他对象来说就像是字段,可以用属性来获取或设置一个后备字段,后备字段就是由属性所设置的一个字段名 private int number ...
- 【二分图最大匹配】【HDU2063】过山车
[科普]什么是BestCoder?如何参加? 过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- stagefright框架(五)-Video Rendering
AwesomePlayer::onVideoEvent除了透過OMXCodec::read取得解碼後的資料外,還必須將這些資料(mVideoBuffer)傳給video renderer,以便畫到螢幕 ...
- T4 模板 vs2010
参阅:http://dotnet.cnblogs.com/page/78398/ T4模板的定义非常简单,整个模板的内容包括两种形式:静态形式和动态动态.前者就是直接写在模板中作为原样输出的文本,后者 ...
- JS转换Decimal带千分号的字符串显示
var numberChars = "0123456789"; /* Convert to decimal string */ function toDecimalString(v ...