結果

問題 No.212 素数サイコロと合成数サイコロ (2)
ユーザー airisairis
提出日時 2015-05-22 23:12:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,211 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 79,956 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 09:59:31
合計ジャッジ時間 1,307 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;

ll a[] = {2,3,5,7,11,13};
ll b[] = {4,6,8,9,10,12};

map<ll, ll> freq1, freq2;

void dfs1(ll n, ll p) {
	if (n == 0) {
		freq1[p] += 1;
	} else {
		rep(i, 6) {
			dfs1(n-1, p * a[i]);
		}
	}
}

void dfs2(ll n, ll p) {
	if (n == 0) {
		freq2[p] += 1;
	} else {
		rep(i, 6) {
			dfs2(n-1, p * b[i]);
		}
	}
}

ll P, C;
double A = 0.0;
double B = 1.0;

int main() {
	cin >> P >> C;
	rep(i, P+C) B *= 6.0;
	dfs1(P, 1);
	dfs2(C, 1);
	foreach(i, freq1) {
		foreach(j, freq2) {
			//printf("%lld=%lld %lld=%lld\n", i->first, i->second, j->first, j->second);
			A += (i->first * j->first) * (i->second * j->second);
		}
	}
	printf("%.12lf\n", A / B);
	return 0;
}


0