A

A simple question.

We can use a for loop to enumerate the number of basketballs we choose to buy, and then calculate the number of soccer balls we buy and compare them.

#include<bits/stdc++.h>
using namespace std;

int main() {
  int n, a, b, mn = INT_MAX;
  cin >> n >> a >> b;
  for (int i = 0; i * a <= n; ++i) {
    int costA = i * a;
    int tot = n - costA;
    int costB = tot;
    costB /= b; 
    costB *= b;
    int left = n - costA - costB;
    mn = min(mn, left);
  }
  cout << mn;
}