Title Link: http://acm.tju.edu.cn/toj/showp2502.html 2502. Digit Generator Time limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 2426 Accepted Runs: 1579
For a positive integer
N, the digit-sum of
Nis defined as the sum of
Nitself and its digits. When
Mis the digitsum of
N, we call
NA
GeneratorOf
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 does not has any generators and some numbers has more than one generator. For example, the generators of 216 is 198 and 207.
You is to write a program to find the smallest generator of the given integer.
Input
Your program was to read from standard input. The input consists of T test Cases. The number of test cases T is given on the first line of the input. Each test case is takes one line containing an integer n, 1≤ n ≤100,000.
Output
Your program is-to-write to standard output. Print exactly one line for each test case. The line was to contain a generator of N for each test case. If N has multiple generators, print the smallest. If N does not has any generators, print 0.
The following shows sample input and output for three test cases.
Sample Input
32161212005
Output for the Sample Input
19801979
The array applies the water question directly to the code:
1#include <cstdio>2#include <cstring>3#include <string>4 using namespacestd;5 intMain ()6 {7 Charnum[ One];8 intT;9scanf"%d",&T);Ten while(t--) One { Ascanf"%s", num); - intTM =9*strlen (num); - intSum =num[0]-'0'; the for(inti =1; i < strlen (num); i++) - { -sum*=Ten; -sum+= (num[i]-'0'); + } - inttt = SUM-TM; + inti; A for(i = TT; i < sum; i++) at { - intGA =i; - intFlag =0; - while(Ga >0) - { -flag+=ga%Ten; inGA = ga/Ten; - } to if((i+flag) = =sum) + { -printf"%d\n", i); the Break; * } $ }Panax Notoginseng if(I==sum) puts ("0"); - } the return 0 ; +}
Digit Generator (water)