N is a random number, which for some reason, is at least two digits. John Doe, a nondescript man, performs an operation on N: he chops off the last digit to form a new number M, and then finds N −M. This excites him in a hard-to-justify way. He then tells you N −M. Thrilled by the fascinating back-story behind this number, you make it your life goal to figure out what N was.
By the way, John was later eaten by a tiger.
Input
Input consists of multiple lines, one line per case. Each line contains a single positive integer between 10 and 10^18 inclusive, giving the value of N − M. Input is terminated by a line containing ‘0’.
Output
For each case, print one line containing the possible values of N in sorted order. Separate consecutive numbers with a single space.
Sample Input
18
0
Sample Output
19 20
问题链接:UVA10633 Rare Easy Problem
问题简述:
给定一个数N,去掉末尾的数字变成M,已知N-M,求N。
问题分析:
设N=10*M+b,那么N-M=9*M+b,其中0≤b≤9
当9|N-M(9整除N-N),则b只能为0,那么N=10*m=10*(N-M)/9=(N-M)/9+(N-M)
当9|N-M不成立,则N有两个值(推导过程略)
程序说明:
如果实在不明白公式的推导过程,也可以对b进行枚举求出n。
题记:(略)
参考链接:(略)
AC的C++语言程序如下:
/* UVA10633 Rare Easy Problem */
#include <iostream>
using namespace std;
int main()
{
long long nm;
while(cin >> nm && nm) {
if(nm % 9)
cout << nm / 9 + nm << endl;
else
cout << nm / 9 + nm - 1 << " " << nm / 9 + nm << endl;
}
return 0;
}