arezey

math: simplify

Feb 12th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. void simplify (int& a, int& b) {
  2.     while (1) {
  3.         bool repeat = false;
  4.         for (ulong x = 0; x < NUM_PRIMES; x++) {
  5.             ulong i = NUM_PRIMES - x - 1;
  6.            
  7.             ushort prime = g_PrimeNumbers[i];
  8.             if (a <= prime || b <= prime)
  9.                 continue;
  10.            
  11.             if (a % prime == 0 && b % prime == 0) {
  12.                 a /= prime;
  13.                 b /= prime;
  14.                 repeat = true;
  15.                 break;
  16.             }
  17.         }
  18.        
  19.         if (!repeat)
  20.             break;
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment