結果

問題 No.1383 Numbers of Product
ユーザー 蜜蜂蜜蜂
提出日時 2020-12-15 18:54:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 2,077 bytes
コンパイル時間 1,768 ms
コンパイル使用メモリ 174,936 KB
実行使用メモリ 25,644 KB
最終ジャッジ日時 2023-08-14 22:06:38
合計ジャッジ時間 7,083 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 57 ms
21,448 KB
testcase_08 AC 61 ms
21,724 KB
testcase_09 AC 65 ms
23,780 KB
testcase_10 AC 88 ms
23,792 KB
testcase_11 AC 89 ms
23,968 KB
testcase_12 AC 91 ms
24,048 KB
testcase_13 AC 92 ms
23,400 KB
testcase_14 AC 78 ms
22,400 KB
testcase_15 AC 61 ms
23,336 KB
testcase_16 AC 91 ms
23,572 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 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 2 ms
4,376 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 73 ms
21,788 KB
testcase_30 AC 96 ms
24,888 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 16 ms
7,888 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 79 ms
23,300 KB
testcase_36 AC 88 ms
23,368 KB
testcase_37 AC 128 ms
23,632 KB
testcase_38 AC 119 ms
24,440 KB
testcase_39 AC 113 ms
24,140 KB
testcase_40 AC 114 ms
23,532 KB
testcase_41 AC 123 ms
24,812 KB
testcase_42 AC 114 ms
24,660 KB
testcase_43 AC 112 ms
24,704 KB
testcase_44 AC 100 ms
23,716 KB
testcase_45 AC 104 ms
25,644 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 81 ms
24,236 KB
testcase_48 AC 83 ms
23,564 KB
testcase_49 AC 91 ms
25,000 KB
testcase_50 AC 93 ms
23,516 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
#define fi first
#define se second

bool b1(ll n,ll k){
  long double z=(-k+sqrt(k*k+4*n))/2;
  ll check=z+0.5;
  return check*(check+k)==n;
}

int main(){
  ll n,k,m;
  cin>>n>>k>>m;
  if(m>23){
    cout<<0<<endl;
    return 0;
  }
  vector<ll> more2;
  ll start,flag;
  for(ll i=2;i<=20;i++){
    start=1;
    flag=0;
    while(flag==0){
      ll x=start;
      for(ll j=1;j<=i;j++){
        if(n/x<start+j*k){
          flag++;
          break;
        }
        x*=(start+j*k);
      }
      start++;
      if(x<=n&&flag==0){
        more2.push_back(x);
      }
    }
  }
  
  if(more2.size()==0){
    if(m>1){
      cout<<0<<endl;
      return 0;
    }
    else{
      ll ok=-1,ng=1e12;
      while(ng-ok>1){
        ll check=(ok+ng)/2;
        if(check<=n/(check+k)){
          ok=check;
        }
        else{
          ng=check;
        }
      }
      cout<<ok<<endl;
      return 0;
    }
  }
  sort(more2.begin(),more2.end());
  vector<vector<ll>> s(25);
  int now=0;
  while(now<more2.size()){
    ll x=more2[now];
    int z=0;
    while(more2[now]==x&&now<more2.size()){
      z++;
      now++;
    }
    s[z].push_back(x);
  }
  
  if(m==1){
    ll ok=-1,ng=1e9;
    while(ng-ok>1){
      ll check=(ok+ng)/2;
      if(check<=n/(check+k)){
        ok=check;
      }
      else{
        ng=check;
      }
    }
    ll ans=s[1].size()+ok;
    if(s[1].size()>0){
      for(ll x:s[1]){
        if(b1(x,k)==true){
          ans--;
        }
      }
    }
    ll w=0;
    for(int i=0;i<25;i++){
      if(s[i].size()>0){
        for(ll x:s[i]){
          if(b1(x,k)==true){
            w++;
          }
        }
      }
    }
    cout<<ans-w<<endl;
    return 0;
  }
  else{
    ll ans=0;
    if(s[m].size()>0){
      for(ll x:s[m]){
        if(b1(x,k)==false){
          //cout<<x<<endl;
          ans++;
        }
      }
    }
    if(s[m-1].size()>0){
      for(ll x:s[m-1]){
        if(b1(x,k)==true){
          //cout<<x<<endl;
          ans++;
        }
      }
    }
    cout<<ans<<endl;
  }
}
0