kburnik

Zadatak Kusac - honi-2013-2014-1

Sep 28th, 2013
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Zadatak: Kusac
  3.              http://bit.ly/honi-2013-2014-1
  4.  
  5.     Datum: 2013-09-28
  6.        
  7.     Autor zadatka: HSIN/HONI
  8.  
  9.     Autor rješenja: Kristijan Burnik, udruga informaticara Božo Težak
  10.  
  11.     Gmail: kristijanburnik
  12.  
  13. */
  14. #include <iostream>
  15.  
  16. using namespace std;
  17.  
  18. int gcd(int a, int b) {
  19.     if (b == 0)
  20.        return a;
  21.     else
  22.        return gcd(b, a % b);
  23. }
  24.  
  25. int main() {
  26.  
  27.     int n,m;
  28.    
  29.     cin >> n >> m;
  30.    
  31.     n %= m;
  32.    
  33.     if ( n % m == 0) {
  34.         cout << 0;
  35.     } else if (m % n == 0) {
  36.         cout << m - n;
  37.     } else {
  38.         int g = gcd(n,m);
  39.         n /= g; m /= g;
  40.    
  41.         cout << ( m / n ) * n;
  42.     }
  43.    
  44.     cout << endl;
  45.    
  46.     // main();
  47.     return 0;
  48. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×