Submission #11526863


Source Code Expand

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i=1; i*i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    int ans = 0;
    auto res = divisor(N);
    auto res2 = divisor(N-1);
    REP(i,res.size()){
        if(res[i] == 1) continue;
        ll tmp = N;
        while(tmp > 1){
            if(tmp % res[i] == 0) tmp /= res[i];
            else{
                tmp %= res[i];
                if(tmp < res[i]) break;
            }
        }
        if(tmp == 1) ans++;
    }
    REP(i,res2.size()){
        if(res2[i] == 1) continue;
        ll tmp = N;
        while(tmp > 1){
            if(tmp % res2[i] == 0) tmp /= res2[i];
            else{
                tmp %= res2[i];
                if(tmp < res2[i]) break;
            }
        }
        if(tmp == 1) ans++;
    }
    cout << ans << endl;
}

Submission Info

Submission Time
Task F - Division or Subtraction
User Bondo416
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1846 Byte
Status AC
Exec Time 22 ms
Memory 384 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 25
Set Name Test Cases
Sample sample_01, sample_02, sample_03
All hand_01, hand_02, hand_03, hand_04, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, random_13, random_14, random_15, random_16, random_17, random_18, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
hand_01 AC 22 ms 256 KiB
hand_02 AC 18 ms 384 KiB
hand_03 AC 1 ms 256 KiB
hand_04 AC 3 ms 256 KiB
random_01 AC 1 ms 256 KiB
random_02 AC 1 ms 256 KiB
random_03 AC 1 ms 256 KiB
random_04 AC 17 ms 256 KiB
random_05 AC 21 ms 256 KiB
random_06 AC 22 ms 256 KiB
random_07 AC 17 ms 256 KiB
random_08 AC 9 ms 256 KiB
random_09 AC 2 ms 256 KiB
random_10 AC 2 ms 256 KiB
random_11 AC 22 ms 256 KiB
random_12 AC 16 ms 256 KiB
random_13 AC 5 ms 256 KiB
random_14 AC 10 ms 256 KiB
random_15 AC 7 ms 256 KiB
random_16 AC 18 ms 256 KiB
random_17 AC 19 ms 256 KiB
random_18 AC 9 ms 256 KiB
sample_01 AC 1 ms 256 KiB
sample_02 AC 1 ms 256 KiB
sample_03 AC 13 ms 256 KiB