Code Chef:cool Guys

Source: Internet
Author: User
Tags gcd greatest common divisor integer numeric value range

All submissions to this problem are available.

Given an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that greatest Common Divisor (GCD) of A and b equals to b.

Input

The ' The ' input contains an integer T denoting the number of test cases. The description of T test cases follows. Each test case consists of the a single integer N on a separate line.

Output

For each test case, the output a single line containing probability as a irreducible fraction.

Given an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that greatest Common Divisor (GCD) of A and b equals to b.

Input

The ' The ' input contains an integer T denoting the number of test cases. The description of T test cases follows. Each test case consists of the a single integer N on a separate line.

Output

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

For each test case, the output a single line containing probability as a irreducible fraction.

Example

Input:
3
1
2
3

Output:
1/1
3/4
5/9

Constraints

1<=T<=103

1<=N<=109

This is also a maths problem.

There are two knowledge points:

1 Algorithm for finding GCD

2 The logarithm that is equal to the two number of a numeric value-this is a mathematical formula

It is said that here is a detailed analysis of mathematics, interested in research:

Http://matwbn.icm.edu.pl/ksiazki/mon/mon42/mon4204.pdf

OJ System:

http://www.codechef.com/problems/COOLGUYS/

 Long Long mgcd (long long A, long B) {long long c = 0;  
        while (b) {c = b;  
        b = a% B;  
    A = C;  
return C;  
    Long Long Pairsofcoolguys (long long N) {long long ans = 0;  
    Long Long sq = (long long) sqrt (n);  
    for (Unsigned i = 1; I <= sq; i++) {ans = n/i;  
    Ans = (ans<<1)-sq*sq;  
return ans;  
    } void Coolguys () {long long n = 0;  
    int T = 0;  
    cin>>t;  
        while (t--) {cin>>n;  
        Long PS = Pairsofcoolguys (n);  
        n *= N;  
        Long Long D = MGCD (PS, N);  
    cout << (ps/d) << "/" << (n/d) << "\ n"; }  
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.