can anyone provide java /c/c++ code for following problem
John is very good at mathematics and cryptography. But he has a very bad memory. He maintains positive integers as passwords.However,instead of writing them directly he encrypts them and writes the encrypted password on his desk. He has 25 as a password for some account. He observed 25 when represented in base 15 has two digits.The first is 1(most significant) and the second is 10(least significant). Hence the sum of digits of 25 when represented in base 15 is 11.
(continued in comment...)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
Now he is interested to find the average of sum of digits of the positive integer password P when represented in all bases from 2 to P-1. Thus he calculates an irreducible fraction, which is written in base 10. He has done all the required computations in base 10. He then writes the encrypted password on his desk.
First line contains one integer n, the no of test cases.
From the next line starts the test cases.Each test case contains one line. the line contains an integer password P. 3<=p<=1000.
Output must contain encrypted password i.e. required average value in a/b form, where a is the numerator and b is the denominator.