-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMINDSMnew.cpp
More file actions
80 lines (73 loc) · 1.41 KB
/
MINDSMnew.cpp
File metadata and controls
80 lines (73 loc) · 1.41 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
#include<bits/stdc++.h>
using namespace std;
int sum(long long int a)
{ int sum1=0;
long long 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<<endl;
}
else
{
int counter=0;
arr[0]=n;
long long int j=1;
int count1=2;
while(counter<=10)
{ counter++;
for(int i=0;i<count1;i++)
{
if(j%2==1)
{
arr[j]=sum(arr[(j-1)/2]);
j++;
}
else
{
arr[j]=arr[(j-2)/2]+k;
j++;
}
}
count1*=2;
}
int step=0;
int currentstep=0;
int interval=1;
int f=interval;
long long int ans=n;
for(int i=0;i<j;i++)
{ f--;
if(arr[i]<ans)
{
ans=arr[i];
step=currentstep;
}
//cout<<"-"<<arr[i]<<"-";
if(f==0)
{
interval*=2;
f=interval;
currentstep++;
// cout<<"\n";
}
}
cout<<ans<<" "<<step<<endl;
}
}
}