結果

問題 No.1383 Numbers of Product
ユーザー 蜜蜂蜜蜂
提出日時 2020-12-15 00:39:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,166 bytes
コンパイル時間 1,759 ms
コンパイル使用メモリ 173,280 KB
実行使用メモリ 25,660 KB
最終ジャッジ日時 2023-09-17 16:06:13
合計ジャッジ時間 20,995 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 723 ms
22,444 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1,160 ms
22,992 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
4,376 KB
testcase_32 WA -
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 1,064 ms
23,208 KB
testcase_37 AC 1,265 ms
24,976 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 1,262 ms
23,944 KB
testcase_42 WA -
testcase_43 AC 1,256 ms
23,860 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 1 ms
4,376 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 1,221 ms
24,160 KB
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

bool b1(ll n,ll k){
  ll ok=-1,ng=sqrt(n)+10;
  while(ng-ok>1){
    ll check=(ok+ng)/2;
    if(check<=n/(check+k)){
      ok=check;
    }
    else{
      ng=check;
    }
  }
  if(ok*(ok+k)==n){
    return true;
  }
  else{
    return false;
  }
}

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<<n-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){
          ans++;
        }
      }
    }
    if(s[m-1].size()>0){
      for(ll x:s[m-1]){
        if(b1(x,k)==false){
          ans++;
        }
      }
    }
    cout<<ans<<endl;
  }
}
0