Computer Science, asked by jezz132021, 1 month ago

  Louis was celebrating his 10th Birthday and his parents wished to make his birthday more special by throwing a surprise bash, inviting all their friends, relatives and neighbors. The little mathematics geek Louis has another surprise waiting for him when he had to cut his favorite Choco vanilla cake. The cake is a rectangular cake and it consists of m×n (1≤m, n≤1000) squares. His friends now called him out for a challenge.   The challenge is that, Louis has to break the cake up into 1×1 pieces (individual squares) and find what is the minimum number of times that he breaks the choco vanilla cake, or pieces therefore, in order to achieve this?   Note that he cannot stack pieces of the cake and break them, because the choco vanilla cake is thick. As an example, a 2×2 cake requires 3 breaks. First he can break it in half, then break each of the halves in half. He cannot break it in half, stack the two 1×2 pieces, and then use only one more break to achieve his goal.  
Input Format:
First line of the input consists of an integer, the dimensions m of the choco vanilla cake. Second line of the input consists of an integer, the dimensions n of the choco vanilla cake.

Output Format:
Output the minimum number of times that he breaks the choco vanilla cake Refer sample input and output for formatting specifications. [All text in bold corresponds to input and rest corresponds to output].
Sample Input and Output 1:
Enter m 1 Enter n 2 Minimum number of times is 1
Sample Input and Output 2:
Enter m 2 Enter n 2 Minimum number of times is 3​

Answers

Answered by premdasr362
0

Answer:

२ minimum number of times is ३

Explanation:

enter m१ २ minimum number of times is 1 sample input and output 2

Answered by ravilaccs
2

Answer:

The program is constructed for the given problem statement

Explanation:

Input Format:

First line of the input consists of an integer, the dimensions m of the choco vanilla cake.

Second line of the input consists of an integer, the dimensions n of the choco vanilla cake.

Output Format:

Output the minimum number of times that he breaks the choco vanilla cake

Refer sample input and output for formatting specifications.

Sample Input and Output 1:

Enter m

1

Enter n

2

Minimum number of times is 1

Sample Input and Output 2:

Enter m

2

Enter n

2

Minimum number of times is 3

Approach:

  • Check how many cycles of distribution of cakes are possible from m number of cakes.
  • Calculate the number of cakes for 1 cycle which is
  • sum = n * (n + 1) / 2
  • Now diving M by sum we get cycle count + some remainder.
  • Now check how many remaining cakes are again possible to distribute to x friends.
  • The value of x can be easily achieved by solving quadratic equation
  • remainder = x * (x + 1) / 2

Program

// C++ implementation of the approach

#include<bits/stdc++.h>

using namespace std;

// Function to return the

// remaining count of cakes

int cntCakes(int n, int m)

{

// Sum for 1 cycle

int sum = (n * (n + 1)) / 2;

// no. of full cycle and remainder

int quo = m/sum ;

int rem = m % sum ;

double ans = m - quo * sum ;

double x = (-1 + pow((8 * rem) + 1, 0.5)) / 2;

ans = ans - x * (x + 1) / 2;

       return int(ans);

}

// Driver Code

int main ()

{

int n = 3;

int m = 8;

int ans = cntCakes(n, m);

cout << (ans);

}

Learn more C program information:

  • https://brainly.in/question/23488510
  • https://brainly.in/question/16043513
Similar questions