結果

問題 No.1383 Numbers of Product
ユーザー umezo
提出日時 2021-02-07 22:59:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,188 bytes
コンパイル時間 3,349 ms
コンパイル使用メモリ 199,392 KB
最終ジャッジ日時 2025-01-18 15:38:03
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 24 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

const double EPS=1e-9;

ll n,k,m;

double g(ll x){
  if(n<1e6) return false;
  double l=0;
  double r=1e18;
  rep(i,50){
    double a=(l+r)/2;
    if(a*a+k*a-x>EPS) r=a;
    else if(a*a+k*a-x<-EPS) l=a;
  }
  return r;
}

double t;

bool f(ll x){
  if(n<t) return false;
  double l=1e6;
  double r=t;
  rep(i,50){
    double a=(l+r)/2;
    if(a*a+k*a-x>EPS) r=a;
    else if(a*a+k*a-x<-EPS) l=a;
  }
  if(abs(r-round(r))<EPS) return true;
  else return false;
}

int main(){
  cin>>n>>k>>m;
  
  map<ll,ll> M;
  for(ll a=1;a<1000000;a++){
    ll tmp=a;
    for(ll b=1;;b++){
      if(log(tmp)+log(a+b*k)>log(n)) break;
      tmp*=a+b*k;
      M[tmp]++;
    }
  }
  
  t=g(n);
  
  ll ans=0;
  if(m>=2){
    for(auto x:M){
      if(x.second==m && f(x.first)==false) ans++;
      if(x.second==m-1 && f(x.first)==true) ans++;
    }
  }
  if(m==1){
    ans+=max(0LL,(ll)t-1000000LL);
    for(auto x:M){
      if(f(x.first)==true) ans--;
      if(x.second==m && f(x.first)==false) ans++;
    } 
  }
  cout<<ans<<endl;
    
  return 0;
}
0