24h購物| | PChome| 登入
2012-04-21 11:29:41| 人氣2,292| 回應0 | 上一篇 | 下一篇

[UVA] 11879 - Multiple of 17

推薦 0 收藏 0 轉貼0 訂閱站台


  Multiple of 17 

Theorem: If you drop the last digit d of an integer n (n$ ge$10), subtract 5d from the remaining integer, then the difference is a multiple of 17 if and only if n is a multiple of 17.

For example, 34 is a multiple of 17, because 3-20=-17 is a multiple of 17; 201 is not a multiple of 17, because 20-5=15 is not a multiple of 17.

Given a positive integer n, your task is to determine whether it is a multiple of 17.

Input 

There will be at most 10 test cases, each containing a single line with an integer n ( 1$ le$n$ le$10100). The input terminates with n = 0, which should not be processed.

Output 

For each case, print 1 if the corresponding integer is a multiple of 17, print 0 otherwise.

Sample Input 

34
201
2098765413
1717171717171717171717171717171717171717171717171718
0

Sample Output 

1
0
1
0


大數除小數, 模擬即可
#include <stdio.h>

int main() {
char str[102];
while(gets(str)) {
if(str[0] == '0' && str[1] == '\0')
break;
int tmp = 0, i;
for(i = 0; str[i]; i++) {
tmp = tmp*10 + str[i]-'0';
tmp %= 17;
}
printf("%d\n", tmp == 0);
}
return 0;
}

台長: Morris
人氣(2,292) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][Random] 10167 - Birthday Cake
此分類上一篇:[UVA][hash] 1152 - 4 Values whose Sum is 0

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文