Advertisement
Mirbek

ПРОИЗВЕДЕНИЕ (Областная олимпиада 2019, день 1)

Feb 11th, 2022
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int a, b, c, p = 1;
  7.     cin >> a >> b >> c;
  8.  
  9.     if (b > c) swap(b, c);
  10.  
  11.     if ((b == 2 && c == 3) || b == 1) {
  12.         while (a % c != 0 && a > 0) {
  13.             a -= b;
  14.             p = (p * b) % 1000;
  15.         }
  16.         while (a > 0) {
  17.             a -= c;
  18.             p = (p * c) % 1000;
  19.         }
  20.     } else {
  21.         while (a % b != 0 && a > 0) {
  22.             a -= c;
  23.             p = (p * c) % 1000;
  24.         }
  25.         while (a > 0) {
  26.             a -= b;
  27.             p = (p * b) % 1000;
  28.         }
  29.     }
  30.  
  31.     if (a != 0) {
  32.         cout << -1 << endl;
  33.     } else {
  34.         cout << p << endl;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement