Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 399 Weeks Ago, 1 Day Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 17 Sep 2017 My Price 8.00

space separated integers

You will be given a rooted tree consisting of n nodes. All the nodes are numbered from 0 to n-1. Root of the tree is always 0.
Each node contains the value of factorial of its node number mod 10 9 +7. For example,if node number is 3, then it will contain 3!=6 mod 10 9 +7 which is equal to 6.
You will be given q queries consisting of two space separated integers a and b, both denoting the node number.
Your task is to count the number of nodes on the path from a to b whose value is divisible by 3.

Input

  • The first line of the input contains an integer n denoting the number of nodes in tree.
  • Then, n-1 lines follows each consisting of two space separated integers denoting the edge of the tree.
  • Next line contains an integer q denoting the number of queries.
  • Then q lines follows each consisting of two space separated integers a and b.

    Output

    For each test case output the required answer.

    Constraints

    • 1 = n = 100000
    • 1 = q = 100000
    • 0 = a,b = n-1

    Example

    Input: 6 0 1 0 2 1 5 2 3 2 4 3 0 4 1 2 3 4 Output: 1 0 2

    Explanation

    Example case 1. For the first query, the path is 0->2->4 of which only 4!=24 is divisible by 3, so output is 1.
    For the second query,the path is 1->0->2 of which none is divisible by 3,so the output is 0.
    For the third query,the path is 3->2->4 of which 3!=6 and 4!=24 are divisible by 3,so the output is 2.

 

Answers

(5)
Status NEW Posted 17 Sep 2017 12:09 PM My Price 8.00

Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll

Not Rated(0)