Contest Duration: - (local time) (100 minutes) Back to Home

Submission #855737

Source Code Expand

Copy
```#include <bits/stdc++.h>

#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

inline ll check(ll b,ll n){
ll ret=0LL;
while(n) ret+=n%b,n/=b;
return ret;
}

int main(void){
ll n,s;
cin >> n >> s;

ll ans=n+2;

for(ll b=2;b*b<=n;++b){
ll res=check(b,n);
if(res==s) chmin(ans,b);
}

for(ll x=1;x*x<=n;++x){
ll y=s-x;
if(y<0||n-y<0) continue;
if((n-y)%x==0){
ll b=(n-y)/x;
if(x<b&&y<b) chmin(ans,b);
}
}

if(n==s) ans=n+1;
if(ans==n+2) ans=-1;
cout << ans << endl;
return 0;
}```

#### Submission Info

Submission Time 2016-08-28 21:31:17+0900 D - Digit Sum Hec C++14 (GCC 5.4.1) 500 1624 Byte AC 28 ms 256 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
 AC × 5
 AC × 47
Set Name Test Cases
Case Name Status Exec Time Memory
subtask1_100000000000_1.txt AC 22 ms 256 KB
subtask1_100000000000_100000000000.txt AC 28 ms 256 KB
subtask1_100000000000_2.txt AC 22 ms 256 KB
subtask1_100000000000_3.txt AC 22 ms 256 KB
subtask1_100000000000_50000000000.txt AC 28 ms 256 KB
subtask1_100000000000_50000000001.txt AC 28 ms 256 KB
subtask1_100000000000_99999999999.txt AC 28 ms 256 KB
subtask1_16983563041_1.txt AC 11 ms 256 KB
subtask1_1_1.txt AC 4 ms 256 KB
subtask1_1_2.txt AC 4 ms 256 KB
subtask1_1_31415926535.txt AC 4 ms 256 KB
subtask1_239484768_194586924.txt AC 5 ms 256 KB
subtask1_2_1.txt AC 4 ms 256 KB
subtask1_2_2.txt AC 4 ms 256 KB
subtask1_31415926535_1.txt AC 14 ms 256 KB
subtask1_49234683534_2461734011.txt AC 20 ms 256 KB
subtask1_4_1.txt AC 4 ms 256 KB
subtask1_58640129658_232122496.txt AC 22 ms 256 KB
subtask1_68719476735_35.txt AC 19 ms 256 KB
subtask1_68719476735_36.txt AC 19 ms 256 KB
subtask1_68719476735_37.txt AC 19 ms 256 KB
subtask1_68719476736_1.txt AC 19 ms 256 KB
subtask1_68719476736_2.txt AC 19 ms 256 KB
subtask1_72850192441_16865701.txt AC 24 ms 256 KB
subtask1_79285169301_27.txt AC 20 ms 256 KB
subtask1_82914867733_1676425945.txt AC 25 ms 256 KB
subtask1_8594813796_75700.txt AC 10 ms 256 KB
subtask1_87654_12345.txt AC 4 ms 256 KB
subtask1_87654_138.txt AC 4 ms 256 KB
subtask1_87654_30.txt AC 4 ms 256 KB
subtask1_87654_4294967308.txt AC 4 ms 256 KB
subtask1_87654_45678.txt AC 4 ms 256 KB
subtask1_97822032312_49157112.txt AC 27 ms 256 KB
subtask1_98750604051_977728851.txt AC 27 ms 256 KB
subtask1_99999515529_1.txt AC 22 ms 256 KB
subtask1_99999515529_316226.txt AC 27 ms 256 KB
subtask1_99999515529_316227.txt AC 27 ms 256 KB
subtask1_99999515529_316228.txt AC 27 ms 256 KB
subtask1_99999515529_49999757765.txt AC 28 ms 256 KB
subtask1_99999515529_49999757766.txt AC 27 ms 256 KB
subtask1_99999515530_2.txt AC 22 ms 256 KB
subtask1_99999999977_1.txt AC 22 ms 256 KB
subtask1_99999999977_2.txt AC 22 ms 256 KB
subtask1_99999999977_49999999989.txt AC 27 ms 256 KB
subtask1_99999999977_49999999990.txt AC 28 ms 256 KB
subtask1_99999999999_1.txt AC 22 ms 256 KB
subtask1_99999999999_100000000000.txt AC 28 ms 256 KB