Advertisement
gamezovladislav

task1

Oct 23rd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void foo(long x) {
  6.     if (x < 10) cout << 0;
  7.     if (x < 100) cout << 0;
  8.     if (x < 1000) cout << 0;
  9.     if (x < 10000) cout << 0;
  10.     if (x < 100000) cout << 0;
  11. }
  12.  
  13. int main() {
  14.     long n;
  15.     cin >> n;
  16.     long m;
  17.     cin >> m;
  18.     if (n == 0) {
  19.         foo(1);
  20.         cout << 1;
  21.         exit(0);
  22.     }
  23.     if (n >= m) {
  24.         foo(0);
  25.         cout << 0;
  26.     } else {
  27.         long x = 1;
  28.         for (long i = 1; i <= n; i++) {
  29.             x *= i;
  30.             x %= m;
  31.         }
  32.         foo(x);
  33.         cout << x;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement