1087: 數字整除
[Submit][Status][Web Board]
Description
定理:把一個至少兩位的正整數的個位數字去掉,再從餘下的數中減去個位數的5倍。當且僅當差是17的倍數時,原數也是17的倍數 。
例如,34是17的倍數,因為3-20=-17是17的倍數;201不是17的倍數,因為20-5=15不是17的倍數。輸入一個正整數n,你的任務是判斷它是否是17的倍數。
Input
輸入文件最多包含10組測試數據,每個數據占一行,僅包含一個正整數n(1<=n<=10100),表示待判斷的正整數。n=0表示輸入結束,你的程序不應當處理這一行。
Output
對於每組測試數據,輸出一行,表示相應的n是否是17的倍數。1表示是,0表示否。
Sample Input
34
201
2098765413
17171717171717171717171717171717171717171717171717180
201
2098765413
17171717171717171717171717171717171717171717171717180
Sample Output
1
0
1
0
0
1
0
#include <iostream>
#include <string>
using
namespace
std;
int
main()
{
string str;
int
tmp, i = 0;
while
(cin >> str && str !=
"0"
)
{
//從頭到尾掃一遍
i = 0;
tmp = 0;
while
(i < str.size())
{
tmp = (tmp * 10 + (str[i] -
'0'
)) % 17;
i ++;
}
if
(tmp % 17 == 0)
cout << 1 << endl;
else
cout << 0 << endl;
}
return
0;
}
/**************************************************************
Problem: 1087
User: 1006440533
Language: C++
Result: Accepted
Time:0 ms
Memory:1272 kb
****************************************************************/
最後更新:2017-04-02 15:14:57