結果

問題 No.1383 Numbers of Product
ユーザー SSRSSSRS
提出日時 2021-02-07 21:08:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 590 ms / 2,000 ms
コード長 1,896 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 172,768 KB
実行使用メモリ 68,336 KB
最終ジャッジ日時 2023-08-14 22:07:54
合計ジャッジ時間 16,732 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 315 ms
43,204 KB
testcase_08 AC 313 ms
42,628 KB
testcase_09 AC 288 ms
51,988 KB
testcase_10 AC 523 ms
67,600 KB
testcase_11 AC 548 ms
66,588 KB
testcase_12 AC 563 ms
67,300 KB
testcase_13 AC 534 ms
64,888 KB
testcase_14 AC 432 ms
55,248 KB
testcase_15 AC 331 ms
45,456 KB
testcase_16 AC 519 ms
67,060 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 407 ms
53,184 KB
testcase_30 AC 529 ms
68,336 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 71 ms
16,668 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 402 ms
62,680 KB
testcase_36 AC 483 ms
59,872 KB
testcase_37 AC 590 ms
68,168 KB
testcase_38 AC 564 ms
68,236 KB
testcase_39 AC 461 ms
68,308 KB
testcase_40 AC 435 ms
68,188 KB
testcase_41 AC 577 ms
68,180 KB
testcase_42 AC 549 ms
68,316 KB
testcase_43 AC 549 ms
68,176 KB
testcase_44 AC 422 ms
68,172 KB
testcase_45 AC 581 ms
68,164 KB
testcase_46 AC 1 ms
4,384 KB
testcase_47 AC 536 ms
66,652 KB
testcase_48 AC 539 ms
67,240 KB
testcase_49 AC 564 ms
68,004 KB
testcase_50 AC 569 ms
67,808 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 1 ms
4,380 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