結果

問題 No.1383 Numbers of Product
ユーザー SSRSSSRS
提出日時 2021-02-07 21:08:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 499 ms / 2,000 ms
コード長 1,896 bytes
コンパイル時間 1,617 ms
コンパイル使用メモリ 174,000 KB
実行使用メモリ 68,480 KB
最終ジャッジ日時 2024-05-02 10:13:33
合計ジャッジ時間 14,568 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 303 ms
43,392 KB
testcase_08 AC 305 ms
42,880 KB
testcase_09 AC 278 ms
52,224 KB
testcase_10 AC 499 ms
67,712 KB
testcase_11 AC 494 ms
66,688 KB
testcase_12 AC 494 ms
67,456 KB
testcase_13 AC 471 ms
64,768 KB
testcase_14 AC 378 ms
55,424 KB
testcase_15 AC 300 ms
45,568 KB
testcase_16 AC 470 ms
66,944 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 370 ms
53,120 KB
testcase_30 AC 487 ms
68,096 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 63 ms
16,768 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 333 ms
62,464 KB
testcase_36 AC 420 ms
60,032 KB
testcase_37 AC 483 ms
68,352 KB
testcase_38 AC 495 ms
68,224 KB
testcase_39 AC 370 ms
68,352 KB
testcase_40 AC 366 ms
68,480 KB
testcase_41 AC 488 ms
68,352 KB
testcase_42 AC 493 ms
68,352 KB
testcase_43 AC 493 ms
68,352 KB
testcase_44 AC 371 ms
68,224 KB
testcase_45 AC 488 ms
68,352 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 468 ms
66,816 KB
testcase_48 AC 473 ms
67,328 KB
testcase_49 AC 478 ms
68,096 KB
testcase_50 AC 473 ms
67,968 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
bool ok(long long K, long long X){
  long long tv = 1000000000;
  long long fv = 0;
  while (tv - fv > 1){
    long long mid = (tv + fv) / 2;
    double prod = 1;
    prod *= mid;
    prod *= mid + K;
    if (prod > X * 2){
      tv = mid;
    } else {
      long long prod2 = 1;
      prod2 *= mid;
      prod2 *= mid + K;
      if (prod2 >= X){
        tv = mid;
      } else {
        fv = mid;
      }
    }
  }
  return tv * (tv + K) == X;
}
int main(){
  long long N, K, M;
  cin >> N >> K >> M;
  map<long long, int> mp;
  int B = 2;
  while (true){
    long long A = 1;
    while (true){
      double prod = 1;
      for (int i = 0; i <= B; i++){
        prod *= A + K * i;
      }
      if (prod > N * 2){
        break;
      }
      long long prod2 = 1;
      for (int i = 0; i <= B; i++){
        prod2 *= A + K * i;
      }
      if (prod2 > N){
        break;
      }
      mp[prod2]++;
      A++;
    }
    if (A == 1){
      break;
    }
    B++;
  }
  if (M >= 2){
    int ans = 0;
    for (auto P : mp){
      long long x = P.first;
      int cnt = P.second;
      if (cnt == M - 1 && ok(K, x) || cnt == M && !ok(K, x)){
        ans++;
      }
    }
    cout << ans << endl;
  } else {
    long long tv = 0;
    long long fv = 1000000000;
    while (fv - tv > 1){
      long long mid = (tv + fv) / 2;
      double prod = 1;
      prod *= mid;
      prod *= mid + K;
      if (prod > N * 2){
        fv = mid;
      } else {
        long long prod2 = 1;
        prod2 *= mid;
        prod2 *= mid + K;
        if (prod2 <= N){
          tv = mid;
        } else {
          fv = mid;
        }
      }
    }
    long long ans = tv;
    for (auto P : mp){
      long long x = P.first;
      int cnt = P.second;
      if (ok(K, x)){
        ans--;
      } else if (cnt == 1){
        ans++;
      }
    }
    cout << ans << endl;
  }
}
0