Submission #2638491

Source Code Expand

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define TARGET 2000000000000LL

bool p(ll a0, ll k, ll x) {
    ll m = k+1;
    // assert(m >= 2);

    ll m_pow_i=1, s=0;
    for (ll i=0; i<x; ++i) {
        s += m_pow_i;
        if (s >= TARGET) return true;
        m_pow_i *= m;
    }
    assert(s < TARGET);
    // m_pow_i = m^x
    // s = (m^x - 1)/(m-1)
    // sk = s(m-1) = (m^x-1) < TARGET x 1e6 = 2e18 (LL)
    // m^x = sk + 1
    assert(m_pow_i == s*k + 1);

    ll diff = TARGET - s;
    // m_pow_i * a0 >= diff ??
    if (diff <= 0) return true;
    // diff > 0
    if (a0 == 0) return false;
    // a0 >= 1
//    if (m_pow_i >= diff) return true;
    if (m_pow_i >= (diff+a0-1)/a0) return true;

    long double left = logl(m)*x + logl(a0);
    long double right = logl(diff);
    return (left >= right);
}

ll solve(ll a0, ll k) {
    if (k == 0) return TARGET - a0;

    ll lo=0, hi=TARGET+1; // p(lo)=X, p(hi)=O
    while (lo+1 < hi){
        ll mi = mid(lo,hi);
        if (p(a0,k,mi)) hi = mi;
        else lo = mi;
    }
    return hi;
}

int main() {
    ll a,k; cin >>a>>k;
    cout<< solve(a,k)<< endl;
    return 0;
}

Submission Info

Submission Time
Task A - 2兆円
User naoya_t
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2218 Byte
Status
Exec Time 2 ms
Memory 256 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 100 / 100 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 1 ms 256 KB
02.txt 1 ms 256 KB
03.txt 1 ms 256 KB
04.txt 1 ms 256 KB
05.txt 1 ms 256 KB
06.txt 1 ms 256 KB
07.txt 1 ms 256 KB
08.txt 1 ms 256 KB
09.txt 1 ms 256 KB
10.txt 1 ms 256 KB
11.txt 1 ms 256 KB
12.txt 1 ms 256 KB
13.txt 1 ms 256 KB
s1.txt 2 ms 256 KB
s2.txt 1 ms 256 KB
s3.txt 1 ms 256 KB