多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

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

UVa 1583 Digit Generator(數學)

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


題意 如果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



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 国产在线观看福利 | 欧美成人免费一区在线播放 | 在线观看视频在线 | 欧美午夜性刺激在线观看免费 | 欧美亚洲另类在线观看 | 日本一级淫片aaaaaa | 精品1州区2区3区4区产品乱码 | 变态 另类 国产 亚洲 | 国产精品久久一区一区 | 操操网站 | 亚洲系列_1页_mmyy11 | 久草香蕉视频在线观看 | 色欧美亚洲 | 欧美video粗暴变态 | 中文字幕第8页 | 97精品国产综合久久久久久欧美 | 久久精品视频一区二区三区 | 五月婷婷激情四射 | 性欧美videos高清精品 | 最新中文字幕在线 | 美女免费网站视频 | 真实国产精品视频国产网 | 特级黄色淫片 | xxxxxx日本| 亚洲视频一区二区 | 伊人俺去久久涩五月综合 | 在线视频免费观看 | 精品999视频 | 美国一级毛片片aa免 | 一级做a爱免费观看视频 | 四虎一区二区三区精品 | 中国国产一级毛片 | 欧美成综合网网站 | 国产成人精品日本亚洲直接 | 免费一级欧美性大片 | 欧美成人三级一区二区在线观看 | 日本中文字幕乱码免费 | 亚洲精品中文字幕乱码三区 | 国产成人咱精品视频免费网站 | 免费在线观看黄色的网站 | 亚洲一区精品伊人久久伊人 |