日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > UVa 1583 Digit Generator(數學)

UVa 1583 Digit Generator(數學)

來源:程序員人生   發布時間:2014-10-17 03:42:09 閱讀次數:1987次


題意 如果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 ", 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 , 1$ le$N$ le$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



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲一区二区久久久 | 麻豆一区二区 | 黄免费网站 | 成人免费a视频 | 日韩三级| 成人网av| 99久久精品免费看蜜桃的推荐词 | 国产一区在线播放 | 一区二区三区中文 | 国产三级精品三级在线观看国产 | 亚洲精品视频成人 | 日韩专区一区二区 | 99久久毛片免费观看 | 韩日免费视频 | 色婷婷香蕉在线一区二区 | 五月婷婷在线观看 | 超碰97国产精品人人cao | 精品免费国产一区二区三区四区 | 很很鲁在线视频播放影院 | 成人日韩视频 | 一区二区三区久久久 | 伊人国产在线 | www.成人.com | 免费在线a | 国产一区二区三区四区三区四 | 久久久精选 | 成人黄色片在线观看 | 玖玖精品 | 狠狠狠干| 天堂av免费观看 | 国产精品久久久免费看 | 久久国产日韩 | 国产a免费 | 国产精品久久久久婷婷二区次 | 高清一二三区 | 欧美国产综合视频 | 亚洲精品成人在线 | jizzjizz在线观看 | 国产午夜精品一区二区 | 久久久久久国产精品 | 国产区一区 |