結果

問題 No.1383 Numbers of Product
ユーザー umezoumezo
提出日時 2021-02-07 22:52:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 974 bytes
コンパイル時間 3,023 ms
コンパイル使用メモリ 198,848 KB
最終ジャッジ日時 2025-01-18 15:23:11
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
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;
bool f(ll x){
  if(n<1e6) return false;
  double l=1e6;
  double r=n;
  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]++;
    }
  }
  
  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,n-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