-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMINDSM.cpp
More file actions
86 lines (82 loc) · 1.64 KB
/
MINDSM.cpp
File metadata and controls
86 lines (82 loc) · 1.64 KB
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
#include<bits/stdc++.h>
using namespace std;
int sum(long long int a)
{ int sum1=0;
int k=a;
while(k!=0)
{
sum1+=k%10;
k/=10;
}
return sum1;
}
int main()
{
long long int n,k;
long long int arr[100000];
int t;
cin>>t;
while(t--)
{
cin>>n>>k;
if(n==1)
{
cout<<1<<" "<<0<<"\n";
}
else
{
int counter=0;
int actualcounter=0;
long long int actualnumber=n;
int flag=0;
arr[0]=n;
long long int j=1;
int count1=2;
while(1)
{ counter++;
for(int i=0;i<count1;i++)
{
if(j%2==1)
{
arr[j]=sum(arr[(j-1)/2]);
if((n%3==0&&k%3==0)&&(arr[j]==3))
{
flag=1;
break;
}
else
{
if(arr[j]==1)
{
flag=2;
break;
}
}
j++;
}
else
{
arr[j]=arr[(j-2)/2]+k;
if(arr[j]%10==0)
{
flag=3;
break;
}
j++;
}
}
count1*=2;
if(((flag==1)||(flag==2))||(flag==3))
{
break;
}
}
if(flag==1)
cout<<3<<" "<<counter<<"\n";
if(flag==2)
cout<<1<<" "<<counter<<"\n";
if(flag==3)
cout<<1<<" "<<counter+1<<"\n";
}
}
}