#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, long long);
int /*<<< orphan*/ scanf(char *, long long *, long long *);
int main() {
  long long N, P;
  scanf("%lld %lld", &N, &P);
  long long i, res = 1;
  if (N == 1) {
    printf("%lld\n", N % P);
    return 0;
  }
  for (i = 2; i <= N; i++) {
    res = res * i % P;
    if (res == 0)
      break;
  }
  printf("%lld\n", res);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <scanf@plt>
movq   $0x1,-0x28(%rbp)
cmpq   $0x1,-0x10(%rbp)
jne    117b <main+0x5b>
mov    -0x10(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rdx,%rsi
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11da <main+0xba>
movq   $0x2,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jg     11ca <main+0xaa>
mov    -0x28(%rbp),%rax
imul   -0x20(%rbp),%rax
cqto
idivq  -0x18(%rbp)
mov    %rdx,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b4 <main+0x94>
jmp    11ca <main+0xaa>
jmp    11b9 <main+0x99>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1183 <main+0x63>
mov    -0x28(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xed5(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <scanf@plt>
mov    0x10(%rsp),%rax
cmp    $0x1,%rax
jne    115f <main+0x3f>
mov    0x8(%rsp),%rcx
mov    %rcx,%rax
shr    $0x20,%rax
je     11bf <main+0x9f>
mov    $0x1,%eax
xor    %edx,%edx
idiv   %rcx
jmp    11cc <main+0xac>
mov    $0x1,%edx
jle    11cc <main+0xac>
mov    0x8(%rsp),%rcx
mov    $0x1,%edx
mov    $0x1,%esi
sub    %rax,%rsi
mov    $0x2,%edi
nopl   (%rax)
imul   %rdi,%rdx
mov    %rdx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     11a0 <main+0x80>
mov    %rdx,%rax
cqto
idiv   %rcx
test   %rdx,%rdx
jne    11ab <main+0x8b>
jmp    11ca <main+0xaa>
nop
mov    %edx,%eax
xor    %edx,%edx
div    %ecx
test   %rdx,%rdx
je     11ca <main+0xaa>
lea    (%rsi,%rdi,1),%rax
add    $0x1,%rax
add    $0x1,%rdi
cmp    $0x2,%rax
jne    1180 <main+0x60>
jmp    11cc <main+0xac>
mov    $0x1,%eax
xor    %edx,%edx
div    %ecx
jmp    11cc <main+0xac>
xor    %edx,%edx
lea    0xe37(%rip),%rdi
mov    %rdx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%lld %lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64* %2, i64* %3)
store i64 1, i64* %5
%7 = load i64, i64* %2
%8 = icmp eq i64 %7, 1
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i64, i64* %2
%11 = load i64, i64* %3
%12 = srem i64 %10, %11
%13 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %12)
store i32 0, i32* %1
br label %35
14: ; preds = %0
store i64 2, i64* %4
br label %15
15: ; preds = %29, %14
%16 = load i64, i64* %4
%17 = load i64, i64* %2
%18 = icmp sle i64 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i64, i64* %5
%21 = load i64, i64* %4
%22 = mul nsw i64 %20, %21
%23 = load i64, i64* %3
%24 = srem i64 %22, %23
store i64 %24, i64* %5
%25 = load i64, i64* %5
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %19
br label %32
28: ; preds = %19
br label %29
29: ; preds = %28
%30 = load i64, i64* %4
%31 = add nsw i64 %30, 1
store i64 %31, i64* %4
br label %15
32: ; preds = %27, %15
%33 = load i64, i64* %5
%34 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %33)
br label %35
35: ; preds = %32, %9
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [10 x i8] c"%lld %lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
%4 = bitcast i64* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64* %1, i64* %2)
%6 = load i64, i64* %1
%7 = icmp eq i64 %6, 1
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = icmp slt i64 %6, 2
br i1 %9, label %24, label %10
10: ; preds = %8
%11 = load i64, i64* %2
br label %18
12: ; preds = %0
%13 = load i64, i64* %2
%14 = srem i64 1, %13
br label %24
15: ; preds = %18
%16 = add nuw i64 %20, 1
%17 = icmp eq i64 %20, %6
br i1 %17, label %24, label %18
18: ; preds = %10, %15
%19 = phi i64 [ 1, %10 ], [ %22, %15 ]
%20 = phi i64 [ 2, %10 ], [ %16, %15 ]
%21 = mul nsw i64 %19, %20
%22 = srem i64 %21, %11
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %15
24: ; preds = %18, %15, %8, %12
%25 = phi i64 [ %14, %12 ], [ 1, %8 ], [ 0, %18 ], [ %22, %15 ]
%26 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %25)
ret i32 0
}