Computer Science, asked by 1326, 1 month ago

1
How to attempt?
Question :
2
3
Cryptic tree
4
5
6
7
8
9
Sherlock received a strange case that had an interesting twist . The murderer had placed the
victim's body on the top of a tree. The tree was a special one with its roots at the top and
leaves at the bottom. As any crime is not perfect, this murderer had left a series of clues in
the leaves and the nodes of the tree. The clues were a series of numbers present at the
leaves and nodes starting from the bottommost leaves and moving up one by one and
Sherlock has to find them and crack them in order to solve the crime. You have to help
Sherlock crack the puzzle.
You are given the set of numbers, but in two of the following different ways:
1. Such that the root is between its children
2. Such that the root is before its children
10
11
12
13
Input Specification:
input1: The number array representing the values in the 1 st way
input2: The number array representing the values in the 2nd
way
input3: Size of the array
Note: In the case where the body is not on the tree, the tree can be empty too.​

Answers

Answered by shilpa85475
20

Sample Input:

4 3

1 2 3 4

1 2 3

13 29 71

Output:

13 754 2769 1508

Explanation:

import java.math.BigInteger;

import java.util.Scanner;

import java.util.StringTokenizer;

public class abc

{

public static void main(String[] args)

{

   Scanner in = new Scanner(System.in);

   String line1 = in.nextLine();

   StringTokenizer st = new StringTokenizer(line1, " ");

   int n = Integer.parseInt(st.nextToken());

   int m = Integer.parseInt(st.nextToken());

   Long[] b = new Long[m];

   String strA = in.nextLine();

   String[] stA = strA.split(" ");

   BigInteger aBI[] = new BigInteger[n];

   for (int ia = 0; ia < stA.length; ia++)

{

       aBI[ia] = new BigInteger(stA[ia]);

   }

   String strB = in.nextLine();

   String[] stB = strB.split(" ");

   for (int ib = 0; ib < stB.length; ib++)

{

       b[ib] = Long.parseLong(stB[ib]);

   }

   String strC = in.nextLine();

   String[] st3 = strC.split(" ");

   for (int ic = 0; ic < m; ic++)

{

       for (int index = b[ic].intValue(); index <= n; index += b[ic]

               .intValue()) {

           aBI[index - 1] = aBI[index - 1].multiply(new BigInteger(st3[ic]));

       }

   }

   for (int ia = 0; ia < n; ia++) {

       aBI[ia] = aBI[ia].mod(new BigInteger("1000000007"));

       System.out.print(aBI[ia] + " ");

   }

}

Similar questions