Submission #858485


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;

#define ll long long
#define SZ(x) ((int)(x).size()) 
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define reveach(i, v) for (__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++ i) 
#define REP(i,a,n) for ( int i=a; i<(n); ++ i )
#define FOR(i,a,n) for ( int i=n-1; i>= int(a);i-- )
#define lson rt<<1, L, m
#define rson rt<<1|1, m, R
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define fi first
#define se second
#define CLR(a, b) memset(a, b, sizeof(a))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

ll n, s;

bool ok(ll b){
    if(b < 2) return false;
    ll x = n;
    ll sum = 0;
    while(x){
        sum += x % b;
        x /= b;
    }
    return sum == s;
}
int main(){
#ifdef ac
	freopen("in.txt","r",stdin);
#endif
	//freopen("out.txt","w",stdout);
    scanf("%lld%lld", &n, &s);
    ll sn = sqrt(n);
    REP(i, 2, sqrt(n) + 1){
        if(ok(i)){
            printf("%d\n", i);
            return 0;
        }
    }
    FOR(q, 1, sqrt(n)){
        if((n - s + q) % q == 0){
            if(ok((n - s + q) / q)){
                printf("%lld\n", (n - s) / q + 1);
                return 0;
            }
        }
    }
    if(n == s){
        printf("%lld\n", n + 1);
        return 0;
    }
    puts("-1");
    return 0;
}

Submission Info

Submission Time
Task C - Tak and Cards
User Cosss
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1802 Byte
Status WA
Exec Time 4 ms
Memory 384 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:54:30: 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 Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 100
Status
WA × 4
WA × 12
WA × 24
Set Name Test Cases
Sample example_01.txt, example_02.txt, example_03.txt, example_04.txt
Subtask1 example_01.txt, example_02.txt, example_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt
All example_01.txt, example_02.txt, example_03.txt, example_04.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt
Case Name Status Exec Time Memory
example_01.txt WA 4 ms 256 KB
example_02.txt WA 4 ms 256 KB
example_03.txt WA 4 ms 256 KB
example_04.txt WA 4 ms 256 KB
subtask1_01.txt WA 4 ms 256 KB
subtask1_02.txt WA 4 ms 256 KB
subtask1_03.txt WA 4 ms 256 KB
subtask1_04.txt WA 4 ms 256 KB
subtask1_05.txt WA 4 ms 256 KB
subtask1_06.txt WA 4 ms 256 KB
subtask1_07.txt WA 4 ms 256 KB
subtask1_08.txt WA 4 ms 256 KB
subtask1_09.txt WA 4 ms 256 KB
subtask2_01.txt WA 4 ms 256 KB
subtask2_02.txt WA 4 ms 384 KB
subtask2_03.txt WA 4 ms 256 KB
subtask2_04.txt WA 4 ms 256 KB
subtask2_05.txt WA 4 ms 256 KB
subtask2_06.txt WA 4 ms 256 KB
subtask2_07.txt WA 4 ms 256 KB
subtask2_08.txt WA 4 ms 256 KB
subtask2_09.txt WA 4 ms 256 KB
subtask2_10.txt WA 4 ms 256 KB
subtask2_11.txt WA 4 ms 256 KB