Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include<iostream>
  3. #include<stdio.h>
  4. #include<conio.h>
  5. using namespace std;
  6.  
  7.  
  8.  
  9. int _tmain(int argc, _TCHAR* argv[])
  10. {
  11. int T;
  12. cin>>T;
  13. int tests[1000];
  14. for(int k=0;k<T;k++) // Take the test cases as input
  15. cin>>tests[k];
  16.  
  17.  
  18.  
  19.  
  20. for(int i=0;i<T;i++) // the main loop that runs T times
  21. {
  22. int N=tests[i];
  23.  
  24. int result=2*N-1; // the numerator of the result
  25.  
  26. int square=N*N; // the denominator of the result
  27.  
  28. for(int j=2;j<=(N/2);j++)
  29. {
  30. result=result+(N/j)-1;
  31. }
  32.  
  33. for(int w=2;w<=result;w++) // Loop to convert fraction into irreducible form
  34. {
  35. if(result%w==0 && square%w==0)
  36. {
  37. result=result/w;
  38. square=square/w;
  39. w--;
  40. }
  41. }
  42.  
  43. cout<<result<<"/"<<square<<endl;
  44.  
  45.  
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement