日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

九余定理(hdu1013)

發布時間:2025/3/15 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 九余定理(hdu1013) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

九余數定理

一個數對九取余后的結果稱為九余數。

一個數的各位數字之和想加后得到的<10的數字稱為這個數的九余數(如果相加結果大于9,則繼續各位相加)

Digital Roots

Time Limit: 2000/1000 MS (Java/Others)????Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 87400????Accepted Submission(s): 27256


Problem Description The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.

For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.

Input The input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.

Output For each integer in the input, output its digital root on a separate line of the output.

Sample Input 24 39 0
Sample Output 6 3
Source Greater New York 2000
#include<stdio.h> #include<string.h> int main() { char num[1000]; int len,sum,i; while(scanf("%s",&num)!=EOF)//這里為什么要字符串輸入呢?原因是因為有一個測試數據很大,int類型肯定過不了,所以在這坑點我wa好幾次{ len=strlen(num); if(len==1 && num[0]=='0') return 0; for(sum=0,i=0;i<len;i++) { sum=sum+num[i]-'0'; } printf("%d\n",sum%9?sum%9:9); } return 0; }

總結

以上是生活随笔為你收集整理的九余定理(hdu1013)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。