Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include<iostream>
- #include<stdio.h>
- #include<conio.h>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- int T;
- cin>>T;
- int tests[1000];
- for(int k=0;k<T;k++) // Take the test cases as input
- cin>>tests[k];
- for(int i=0;i<T;i++) // the main loop that runs T times
- {
- int N=tests[i];
- int result=2*N-1; // the numerator of the result
- int square=N*N; // the denominator of the result
- for(int j=2;j<=(N/2);j++)
- {
- result=result+(N/j)-1;
- }
- for(int w=2;w<=result;w++) // Loop to convert fraction into irreducible form
- {
- if(result%w==0 && square%w==0)
- {
- result=result/w;
- square=square/w;
- w--;
- }
- }
- cout<<result<<"/"<<square<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement