Submission #855593


Source Code Expand

Copy
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll get(ll x, ll y)
    {
    ll s = 0;
    while(x)
        {
        s += x%y;
        x/=y;
    }
    return s;
}
int main()
    {
    ll n,s;
    scanf("%lld%lld",&n,&s);
    set<ll> pos;
    ll x;
    pos.insert(n+1);
    if(n!=1)
    pos.insert(n);
    if(n > s)
        {
        ll dif = n-s;
        
        for(x=2;x*x<=dif;x++)if(dif%x==0)
            {
            pos.insert(x);
            if(x*x!=dif)pos.insert(dif/x);
        }
        pos.insert(dif);
    }
    for(x=2;x*x<=n;x++)pos.insert(x);
    set<ll>::iterator I;
    for(I=pos.begin();I!=pos.end();I++){
      //   printf("checking for %lld\n",*I);
        if(get(n,*I)==s)return printf("%lld\n",*I)*0;
   
}
        return printf("-1\n")*0;
  //  if(s==1)return printf("%lld\n",n)*0;
    
}

Submission Info

Submission Time
Task D - 桁和 / Digit Sum
User codingalgo
Language C++14 (Clang 3.8.0)
Score 0
Code Size 955 Byte
Status

Compile Error

./Main.cpp:5:10: fatal error: 'bits/stdc++.h' file not found
#include <bits/stdc++.h>
         ^
1 error generated.