Understanding the concept
Understanding the Concept
Power of positive integer ??
Understanding the Concept
Power of positive integer ??
Sum of the digits of that integer.
Understanding the Concept
Power of positive integer ??
Sum of the digits of that integer.
Example
17
Understanding the Concept
Power of positive integer ??
Sum of the digits of that integer.
Example
17
1
7
Understanding the Concept
Power of positive integer ??
Sum of the digits of that integer.
Example
17
1
7
+
=
8
Understanding the Concept
Power of positive integer ??
Sum of the digits of that integer.
Example
688952
Understanding the Concept
Power of positive integer ??
Sum of the digits of that integer.
Example
688952
6
8
8
9
5
2
Understanding the Concept
Power of positive integer ??
Sum of the digits of that integer.
Example
688952
6
8
8
9
5
2
+
+
+
+
+
=
38
Understanding the Concept


Understanding the Concept


Final Power for
Chef
Final Power for
Rick
Understanding the Concept


Final Power for
Chef
Final Power for
Rick
Positive integer
Power of integer = Final Power
GOAL
Understanding the Concept


Final Power for
Chef
Final Power for
Rick
Minimum number of digits in positive
integer.
WIN
Understanding the Concept
Final Power = 65
Understanding the Concept
Final Power = 65
Maximum single digit number I can take out
Understanding the Concept
Final Power = 65
Maximum single digit number I can take out
(0-9)
Understanding the Concept
Final Power = 65
Maximum single digit number I can take out
(0-9)
9
Understanding the Concept
65
Understanding the Concept
56
9
Understanding the Concept
47
9
9
Understanding the Concept
38
9
9
9
Understanding the Concept
29
9
9
9
9
Understanding the Concept
20
9
9
9
9
9
Understanding the Concept
11
9
9
9
9
9
9
Understanding the Concept
2
9
9
9
9
9
9
9
Understanding the Concept
0
9
9
9
9
9
9
9
2
Understanding the Concept
0
9
9
9
9
9
9
9
2
65
Understanding the Concept
9
9
9
9
9
9
9
2
FP = 15
FP = 15
5 5 5
FP = 15
5 5 5
96
FP = 15
5 5 5
96
78
Understanding the Concept
while(final_power > 0)
{
if(final_power >= 9)
final_power = final_power - 9
else
final_power = 0
digit++;
}final_power = 82
digit = 0
Understanding the Concept
while(final_power > 0)
{
if(final_power >= 9)
final_power = final_power - 9
else
final_power = 0
digit++;
}final_power = 73
digit = 1
Understanding the Concept
while(final_power > 0)
{
if(final_power >= 9)
final_power = final_power - 9
else
final_power = 0
digit++;
}final_power = 64
digit = 2
Understanding the Concept
while(final_power > 0)
{
if(final_power >= 9)
final_power = final_power - 9
else
final_power = 0
digit++;
}final_power = 55
digit = 3
Understanding the Concept
while(final_power > 0)
{
if(final_power >= 9)
final_power = final_power - 9
else
final_power = 0
digit++;
}final_power = 46
digit = 4
Understanding the Concept
while(final_power > 0)
{
if(final_power >= 9)
final_power = final_power - 9
else
final_power = 0
digit++;
}final_power = 37
digit = 5
Understanding the Concept
while(final_power > 0)
{
if(final_power >= 9)
final_power = final_power - 9
else
final_power = 0
digit++;
}final_power = 28
digit = 6
Understanding the Concept
while(final_power > 0)
{
if(final_power >= 9)
final_power = final_power - 9
else
final_power = 0
digit++;
}final_power = 10
digit = 8
Understanding the Concept
while(final_power > 0)
{
if(final_power >= 9)
final_power = final_power - 9
else
final_power = 0
digit++;
}final_power = 1
digit = 9
Understanding the Concept
while(final_power > 0)
{
if(final_power >= 9)
final_power = final_power - 9
else
final_power = 0
digit++;
}final_power = 0
digit = 10
Understanding the Concept
But is it necessary to use a while loop?
Understanding the Concept
But is it necessary to use a while loop?
Understanding the Concept
73
9
9
9
9
9
9
9
9
1
Understanding the Concept
73
9
9
9
9
9
9
9
9
1
73 / 9 = 8
Understanding the Concept
73
9
9
9
9
9
9
9
9
1
73 / 9 = 8
+
1
=
9 DIGITS
Understanding the Concept
if(final_power%9 == 0)
digits = final_power/9
else
digits = (final_power/9)+1
Understanding the Concept
if(final_power%9 == 0)
digits = final_power/9
else
digits = (final_power/9)+1
102
Understanding the Concept
if(final_power%9 == 0)
digits = final_power/9
else
digits = (final_power/9)+1
102
(102) % 9 != 0
Understanding the Concept
if(final_power%9 == 0)
digits = final_power/9
else
digits = (final_power/9)+1
102
(102) % 9 != 0
(102/9) + 1 = 12
Understanding the Concept
Time Complexity
Naive solution :
Optimised solution :
Coding the Concept
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int pc , pr;
cin >> pc >> pr;
int digit_chef;
int digit_rick;
if(pc%9!=0)
digit_chef = (pc/9)+1;
else
digit_chef = pc/9;
if(pr%9!=0)
digit_rick = (pr/9)+1;
else
digit_rick = pr/9;
if(digit_chef < digit_rick)
cout << "0" << " " << digit_chef << endl;
else
cout << "1" << " " << digit_rick << endl;
}
return 0;
}deck
By Chirayu Jain
deck
- 46