Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- int a, b, c, p = 1;
- cin >> a >> b >> c;
- if (b > c) swap(b, c);
- if ((b == 2 && c == 3) || b == 1) {
- while (a % c != 0 && a > 0) {
- a -= b;
- p = (p * b) % 1000;
- }
- while (a > 0) {
- a -= c;
- p = (p * c) % 1000;
- }
- } else {
- while (a % b != 0 && a > 0) {
- a -= c;
- p = (p * c) % 1000;
- }
- while (a > 0) {
- a -= b;
- p = (p * b) % 1000;
- }
- }
- if (a != 0) {
- cout << -1 << endl;
- } else {
- cout << p << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement