結果

問題 No.3034 7 problems
ユーザー FF256grhyFF256grhy
提出日時 2018-04-02 19:00:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 3,997 bytes
コンパイル時間 2,621 ms
コンパイル使用メモリ 164,164 KB
実行使用メモリ 4,392 KB
最終ジャッジ日時 2023-09-08 13:31:05
合計ジャッジ時間 5,688 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,380 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 36 ms
4,376 KB
testcase_03 AC 13 ms
4,380 KB
testcase_04 AC 14 ms
4,380 KB
testcase_05 AC 31 ms
4,380 KB
testcase_06 AC 26 ms
4,376 KB
testcase_07 AC 27 ms
4,376 KB
testcase_08 AC 24 ms
4,376 KB
testcase_09 AC 30 ms
4,376 KB
testcase_10 AC 16 ms
4,376 KB
testcase_11 AC 26 ms
4,380 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 23 ms
4,380 KB
testcase_14 AC 22 ms
4,376 KB
testcase_15 AC 21 ms
4,380 KB
testcase_16 AC 21 ms
4,380 KB
testcase_17 AC 23 ms
4,380 KB
testcase_18 AC 44 ms
4,376 KB
testcase_19 AC 25 ms
4,376 KB
testcase_20 AC 27 ms
4,392 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 35 ms
4,376 KB
testcase_23 AC 22 ms
4,376 KB
testcase_24 AC 36 ms
4,376 KB
testcase_25 AC 34 ms
4,376 KB
testcase_26 AC 13 ms
4,380 KB
testcase_27 AC 43 ms
4,380 KB
testcase_28 AC 31 ms
4,380 KB
testcase_29 AC 30 ms
4,376 KB
testcase_30 AC 12 ms
4,380 KB
testcase_31 AC 32 ms
4,380 KB
testcase_32 AC 19 ms
4,380 KB
testcase_33 AC 31 ms
4,376 KB
testcase_34 AC 14 ms
4,376 KB
testcase_35 AC 31 ms
4,376 KB
testcase_36 AC 22 ms
4,376 KB
testcase_37 AC 9 ms
4,380 KB
testcase_38 AC 29 ms
4,376 KB
testcase_39 AC 30 ms
4,380 KB
testcase_40 AC 37 ms
4,376 KB
testcase_41 AC 19 ms
4,376 KB
testcase_42 AC 31 ms
4,380 KB
testcase_43 AC 41 ms
4,380 KB
testcase_44 AC 14 ms
4,380 KB
testcase_45 AC 22 ms
4,380 KB
testcase_46 AC 18 ms
4,376 KB
testcase_47 AC 14 ms
4,376 KB
testcase_48 AC 16 ms
4,380 KB
testcase_49 AC 38 ms
4,380 KB
testcase_50 AC 16 ms
4,376 KB
testcase_51 AC 16 ms
4,376 KB
testcase_52 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL MOD = 1e9 + 7;
LL ex(LL x, LL y, LL mod = MOD) {
	LL z[64], v = 1;
	inc(i, 64) { z[i] = (i == 0 ? x : z[i - 1] * z[i - 1] % mod); }
	inc(i, 64) { if((y >> i) & 1) { (v *= z[i]) %= mod; } }
	return v;
}

LL dp[100001];
LL t;

LL f1(LL n) { return n * n; }
LL f2(LL n) { return n * n * n - n + n * n; }
LL f3(LL n) { return t; }
LL f4(LL n) { return 4 * n * n + 17; }
LL f5(LL n) { return ex(n, n * n * n); }
LL f6(LL n) { return n; }
LL f7(LL n) { return (dp[n] * n) % MOD; }

/*
LL f1(LL n) { return (n * n) % MOD; }
LL f2(LL n) { return ((n * n * n) % MOD + (MOD - n) + n * n) % MOD; }
LL f3(LL n) { return t; }
LL f4(LL n) { return (4 * n * n + 17) % MOD; }
LL f5(LL n) { return ex(n, n * n * n); }
LL f6(LL n) { return n; }
LL f7(LL n) { return (dp[n] * n) % MOD; }
*/

/*
4*10^26
xenon: Xe 54
2*10^2222
2^34
?????

Nchoutennnogurafugaaru.hajime,konogurafunihahennganai.konogurafuniN-1kaisousasuru.Ikaimenosousadeha[1,I]nohannideichiyourannsuuwomochiiteseisuuAwoseiseishi,choutennI+1tochoutennAnoaidanihennwotsuikasuru.sousagaowattaatonihakigadekiteiru.kokode,kinosukoawo,2ijouNikanosubetenoseisuuJnitsuitenochoutenn1tochoutennJnokyorinosouwatoteigisuru.ranndamunikouseisarerukinosukoanokitaichiwoXtoshitatoki,N!Xwo10^9+7dewattaamariwomotomenasai.tadashi,konoataihakanarazuseisuuninarukotogashoumeidekiru.

N 頂点のグラフがある。はじめ、このグラフには辺がない。このグラフに N-1 回操作する。
I 回目の操作では [1, I] の範囲で一様乱数を用いて整数 A を生成し、頂点 I+1 と頂点 A の間に辺を追加する。
操作が終わった後には木が出来ている。
ここで、木のスコアを、 2 以上 N 以下の全ての整数 J についての頂点 1 と頂点 J の距離の総和と定義する。
ランダムに構成される木のスコアの期待値を X としたとき、N!X を 10^9+7 で割った余りを求めなさい。
ただし、この値は必ず整数になることが証明できる。
*/

int main() {
	// dp[i] = OEIS_A001705[i - 1]
	// f7(i) = OEIS_A001705[i - 1] * i  (= OEIS_A006675[i])
	LL f = 1;
	inc1(i, 100000) {
		dp[i] = (i == 1 ? 0 : (dp[i - 1] * i + f) % MOD);
		(f *= i) %= MOD;
	}
	
	cin >> t;
	inc(q, t) {
		if(q != 0) { cout << "\n"; }
		
		LL n;
		cin >> n;
		cout << f1(n) << "\n";
		cout << f2(n) << "\n";
		cout << f3(n) << "\n";
		cout << f4(n) << "\n";
		cout << f5(n) << "\n";
		cout << f6(n) << "\n";
		cout << f7(n) << "\n";
	}
	
	return 0;
}
0