The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 399 Weeks Ago, 1 Day Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
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.
For each test case output the required answer.
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.
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