Submission #1405973


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll func(ll b, ll n) {
	if (n < b)
		return n;
	return func(b, n/b) + n%b;
}

signed main() {

	ll n, s;

	scanf("%lld %lld", &n, &s);

	if (s == n) {
		printf("%d", n + 1);
		return 0;
	}
	else if(s > n){
		printf("-1");
		return 0;
	}

	int sqn = sqrt(n);
	rep(i, 2, sqn+1) {
		int a = func(i, n);
		if (a == s) {
			printf("%d\n", i);
			return 0;
		}
	}
	ll Min = LLONG_MAX;
	rep(i, 1, sqn+1) {
		if(!((n-s)%i))
			if (func(1LL + (n - s) / (ll)i, n) == s) {
				Min = min(Min, 1LL + (n - s) / (ll)i);
				return 0;
			}
	}
	printf("%lld\n", Min == LLONG_MAX ? -1 : Min);
	return 0;
}

Submission Info

Submission Time
Task D - Digit Sum
User Gear
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2148 Byte
Status WA
Exec Time 11 ms
Memory 256 KB

Compile Error

./Main.cpp:9:20: warning: extra tokens at end of #include directive
 #include <stdlib.h>>
                    ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:69:21: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll {aka long long int}’ [-Wformat=]
   printf("%d", n + 1);
                     ^
./Main.cpp:66:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld", &n, &s);
                            ^

Judge Result

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