結果

問題 No.502 階乗を計算するだけ
ユーザー kimiyuki
提出日時 2017-04-18 16:58:28
言語 Bash
(Bash 5.2.21)
結果
RE  
実行時間 -
コード長 1,609 bytes
コンパイル時間 26 ms
コンパイル使用メモリ 6,688 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-07-19 07:38:22
合計ジャッジ時間 1,373 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 52
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#!/bin/bash
cat <<'EOF' > a.cpp
#include <stdio.h>
#include <stdlib.h>
#include <pthread.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;
}
int fact(int n) {
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(&th[i], NULL, fact_thread, (void *)&args[i]);
}
int z = 1;
for (int i = 0; i < 2; ++ i) {
ll *ret;
pthread_join(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;
}
EOF
g++ -std=c++1y -Ofast -march=native -mtune=native a.cpp -lpthread
exec ./a.out
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0