#54665: C++解法


william000000000 (unknown)


#include <iostream>

using namespace std;

int main()
{
    int k, x1, x2, y1, y2, pos = 0;
    cin >> k >> x1 >> y1 >> x2 >> y2;

    while (k > 0) {
        pos += k;

        if (pos % x1 == 0) k -= y1;
        if (pos % x2 == 0) k -= y2;
    }

    cout << pos;
    return 0;
}