CSES - Leirikisa 1 - Results
Submission details
Task:kusac
Sender:Kuha
Submission time:2016-07-27 15:12:53 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:22:21: error: 'gcd' was not declared in this scope
  ans += l / gcd(n, l) - 1;
                     ^

Code

#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define N (1<<17)
#define M 1000000007

using namespace std;

int main () {
  int n, m;
  cin>>n>>m;
  n = n % m;
  int ans = 0;
  if (!n) cout<<0<<endl;
  else if (n < m) {
    int l = m;
    ans += n * (l / n);
    l %= n;
    if (!l) ans -= n;
    if (l) {
      if (n % l) {
	ans += l / gcd(n, l) - 1;
      }
    }
    cout<<ans<<endl;
  }
}