-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSP-Happy numbers 1.cpp
134 lines (104 loc) · 2.68 KB
/
SP-Happy numbers 1.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#include<bits/stdc++.h>
#include<cmath>
#include<cstdlib> //for qsort
#include<cstdio>
#define rep(x,a,b) for(x=a;x<b;x++)
#define reptill(x,a,b) for(x=a;x<=b;x++)
#define scani(x) scanf("%d",&x)
#define scan2i(x,y) scanf("%d %d",&x,&y)
#define scan3i(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define scanfl(x) scanf("%f",&x)
#define scanc(x) scanf("%c",&x)
#define scand(x) scanf("%lf",&x)
#define scanll(x) scanf("%lli",&x)
#define scan2ll(x,y) scanf("%lli %lli",&x,&y)
#define scan3ll(x,y) scanf("%lli %lli %lli",&x,&y,&z);
#define scanl(x) scanf("%ld",&x)
#define scans(x) scanf("%s",x)
#define printi(x) printf("%d\n",x)
#define printl(x) printf("%ld\n",x)
#define printll(x) printf("%lli\n",x)
#define printd(x) printf("%lf\n",x)
#define printfl(x) printf("%f\n",x)
#define printc(x) printf("%c\n",x)
#define prints(x) printf("%s\n",x);
#define sloop(x) loop(i,0,strlen(x)-1)
#define whole(x) x.begin(),x.end()
#define pb push_back
#define newline cout<<"\n"
#define F first
#define S second
#define FILL(A,value) memset(A,value,sizeof(A))
inline bool inc_range(int x,int y,int z) { return ((x>=y)&&(x<=z)); }
inline bool ex_range(int x,int y,int z) { return ((x>y)&&(x<z)); }
inline bool is_either(int x,int y,int z) { return ((x==y)||(x==z)); }
//maths
#define PI acos(-1)
#define INTmax numeric_limits<int>::max()
#define LLmax numeric_limits<ll>::max()
#define ULLmax numeric_limits<ull>::max()
#define INTmin numeric_limits<int>::min()
using namespace std;
template<typename type=int>
void get_arr(type a[],type n) {for(type i=0;i<n;i++) cin>>a[i];}
template<typename type=int>
void show_arr(type a[],type n=1) {for(type i=0;i<n;i++) cout<<a[i]<<" ";}
template<typename type=int>
inline type max3(type a,type b,type c){ return max(max(a,b),c);}
inline void FAST_IO(){ios_base::sync_with_stdio(false);}
#define SIZE int(1e3)+1
#define MOD
#define debug
//#define Online_judge
inline bool ispow10(ll n)
{
double tmpval=log10(n);
if(floor(tmpval)==tmpval) ///nos of forms 10^n
{
return true;
}
return false;
}
int main()
{
FAST_IO();
ifstream cin("ip");
int t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
// cout<<log10(n)<<"\n";
ll ans=1,c=0;
if(ispow10(n))
{
ans=1;
}
else
{
ll tmp=n,sum=0;
while(n!=1)
{
while(n)
{
sum+=(n%10)*(n%10);
n/=10;
}
n=sum;
sum=0;
if(n%2==0 and ispow10(n/2))
{
ans=-1;
break;
}
++c;
}
}
(ans==-1)?cout<<"-1":cout<<c;
newline;
}
}