-
Notifications
You must be signed in to change notification settings - Fork 0
/
10922.cpp
55 lines (51 loc) · 1.02 KB
/
10922.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
10922 - 2 the 9s
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
char ab[1005];
while(scanf("%s",ab)!=EOF)
{
if(((int)ab[0]-48)==0)break;
ll len = strlen(ab);
ll sum=0,cnt=0,rem,deg =1;
for(int i=len-1; i>=0; i--)
{
sum = sum + (int)ab[i]-48;
}
while(sum>9)
{
deg++;
ll b4 = sum;
sum =0;
while(b4)
{
sum+=b4%10;
b4/=10;
}
}
if(sum==9)
{
cout<<ab<<" is a multiple of 9 and has 9-degree "<<deg<<"."<<endl;
}
else
{
cout<<ab<<" is not a multiple of 9."<<endl;
}
}
return 0;
}
/*
Sample Input
999999999999999999999
9
9999999999999999999999999999998
0
Sample Output
999999999999999999999 is a multiple of 9 and has 9-degree 3.
9 is a multiple of 9 and has 9-degree 1.
9999999999999999999999999999998 is not a multiple of 9.
*/