Uva 10975 Fractions Again?

  1. // Uva 10976 Fractions Again?
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. int iNumX, iNumY, iNumK;   
  7. int i,j,iCount;
  8. while ( cin >> iNumK )
  9.     {
  10.     iCount = 0;
  11.     for ( i=iNumK+1 ; i<=2*iNumK ; i++ )    // posibilities of y
  12.         if ( (i*iNumK)%(i-iNumK) == 0 )
  13.             iCount++;
  14.     cout << iCount <<endl;     
  15.     for ( i=iNumK+1 ; i<=2*iNumK ; i++ )    // posibilities of y
  16.         if ( (i*iNumK)%(i-iNumK) == 0 )
  17.             cout << "1/" << iNumK << " = " << "1/" << (i*iNumK)/(i-iNumK) << " + " << "1/" << i  << endl;
  18.     }
  19. }
hint:    
    1/x = 1/k - 1/y   
=>  1/x = y-k / k*y

留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change

codeforces 271A --- beautiful year