結果
問題 | No.502 階乗を計算するだけ |
ユーザー | kimiyuki |
提出日時 | 2017-04-18 16:54:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,096 bytes |
コンパイル時間 | 376 ms |
コンパイル使用メモリ | 35,060 KB |
実行使用メモリ | 4,504 KB |
最終ジャッジ日時 | 2023-09-26 13:15:55 |
合計ジャッジ時間 | 7,938 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | AC | 1 ms
4,376 KB |
testcase_43 | AC | 2 ms
4,376 KB |
testcase_44 | AC | 2 ms
4,376 KB |
testcase_45 | AC | 1 ms
4,380 KB |
testcase_46 | AC | 1 ms
4,376 KB |
testcase_47 | AC | 1 ms
4,376 KB |
testcase_48 | AC | 1 ms
4,380 KB |
testcase_49 | AC | 1 ms
4,376 KB |
testcase_50 | AC | 1 ms
4,380 KB |
testcase_51 | AC | 1 ms
4,380 KB |
ソースコード
#pragma GCC optimize "O3" #pragma GCC target "avx" #include <stdio.h> #include <stdlib.h> typedef long long ll; constexpr int mod = 1e9+7; void *fact_thread(void *args) { int l = ((int *)args)[0]; int r = ((int *)args)[1]; ll y = 1; ll i = l; for (; i & 0x7 and i < r; ++ i) { y = y * i % mod; } { ll x[8]; for (int j = 0; j < 8; ++ j) { x[j] = 1; } for (; i+7 < r; i += 8) { x[0] = x[0] * i % mod; x[1] = x[1] * (i+1) % mod; x[2] = x[2] * (i+2) % mod; x[3] = x[3] * (i+3) % mod; x[4] = x[4] * (i+4) % mod; x[5] = x[5] * (i+5) % mod; x[6] = x[6] * (i+6) % mod; x[7] = x[7] * (i+7) % mod; } for (int j = 0; j < 8; ++ j) { y = y * x[j] % mod; } } for (; i < r; ++ i) { y = y * i % mod; } ll *p = (ll *)malloc(sizeof(ll)); *p = y; return (void *)p; } extern "C" { void* __libc_dlopen_mode(const char *, int); void* __libc_dlsym(void *, const char *); int __libc_dlclose(void *); } typedef unsigned long int pthread_t; int (*pthread_create_ptr)(pthread_t *, pthread_attr_t *, void * (*)(void *), void *); int (*pthread_join_ptr)(pthread_t, void **); int fact(int n) { void *lib = __libc_dlopen_mode("/lib/x86_64-linux-gnu/libpthread.so.0", 2); pthread_create_ptr = (decltype(pthread_create_ptr))__libc_dlsym(lib, "pthread_create"); pthread_join_ptr = (decltype(pthread_join_ptr))__libc_dlsym(lib, "pthread_join"); int args[2][2] = { { 1, (n+1)/2 }, { (n+1)/2, n+1 }, }; pthread_t th[2]; for (int i = 0; i < 2; ++ i) { (*pthread_create_ptr)(&th[i], NULL, fact_thread, (void *)&args[i]); } int z = 1; for (int i = 0; i < 2; ++ i) { ll *ret; (*pthread_join_ptr)(th[i], (void **)&ret); z = z * (*ret) % mod; free(ret); } return z; } int main(void) { ll n; scanf("%lld",&n); printf("%d\n", n == 0 ? 1 : n < mod ? fact(n) : 0); return 0; }