NXS3-Editorial

Practice

Author: Setter’s name
Tester: Tester’s name
Editorialist: Editorialist’s name

DIFFICULTY:

SIMPLE

PROBLEM:

The problem is statement simply says that given an integer N denoting the number of river and temple. You need to find the minimum number of flowers to take and the minimum number of flowers offered to the god. But the condition is that as he crosses every river the number of flowers currently he had to get doubled.He needs to offer an equal number of flowers in every temple and at last, he should left with 0 flowers.

EXPLANATION:

To clarify the problem statement let’s take an example: N=2
for N =2 answer is 3 , 4 (take, offer)

               || ^ || ^

Initially, he has 3 flowers, as he crosses the 1st river the flower gets doubled and it became 6 and on the 1st temple, he offered 4 flowers.
Now he will have 6-4=2 flowers as he crosses the next river it will become 4 and on the next temple, that is last he will offer all the 4 flowers and at last, he will have no flowers left with him as 4-4=0.

To solve this question logically which is based on simple mathematics. We just need to find 2N-1 number of flowers to take and 2N number of flowers to to offer

For more clarification refer to my solution

SOLUTIONS:

Editorialist's Solution
import java.util.Scanner;
import java.io.*;

class NXS3 {
	public static void main (String[] args) {
	Scanner sc = new Scanner(System.in);
	int mod = 1000000007;
	int test = sc.nextInt();
	while(test-->0){
	    int n = sc.nextInt();
	    int ans=1;
	    for(int i=0;i<n;i++)
	    {
	        ans*=2;
	        ans%=mod;
	    }
	    System.out.println(ans-1+" "+ans);
	}
	        
    }
}

Feel free to share your approach, if you want to. (even if it’s same) . Suggestions are welcomed as always had been.