結果

問題 No.575 n! / m / m / m...
ユーザー koba-e964koba-e964
提出日時 2017-10-06 23:12:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,868 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 102,936 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 10:49:32
合計ジャッジ時間 2,253 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

/**
 * For every prime factor p, perform result[p] += e. (where n = \prod p^e)
 * Verified by: Codeforces #400 E
 *              (http://codeforces.com/contest/776/submission/24956471)
 */
void factorize(long long v, std::map<long long, int> &result) {
  long long p = 2;
  while (v > 1 && p * p <= v) {
    int cnt = 0;
    while (v % p == 0) {
      cnt++;
      v /= p;
    }
    if (cnt > 0) {
      if (result.count(p) == 0) {
	result[p] = 0;
      }
      result[p] += cnt;
    }
    p += p == 2 ? 1 : 2;
  }
  if (v > 1) {
    if (result.count(v) == 0) {
      result[v] = 0;
    }
    result[v] += 1;
  }
}

const ll THRESHOLD = 100000;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  map<ll, int> fact;
  factorize(m, fact);
  int mi = 1e8;
  for (auto v: fact) {
    ll p = v.first;
    int e = v.second;
    int einn = 0;
    int k = n;
    while (k > 0) {
      k /= p;
      einn += k;
    }
    mi = min(mi, einn / e);
  }
  double ret = 0;
  if (n < THRESHOLD) {
    REP(i, 1, n + 1) {
      ret += log10(i);
    }
  } else {
    // Stirling's approximation
    ret = n * log10(n / exp(1));
    ret += log10(2 * acos(-1) * n) / 2.0;
  }
  ret -= mi * log10(m);
  ll tenexp = floor(ret);
  ret -= tenexp;
  ret = pow(10, ret);
  cout << ret << "e" << tenexp << "\n";
}
0