結果

問題 No.1312 Snake Eyes
ユーザー bachoppibachoppi
提出日時 2020-12-11 14:29:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,321 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 122,732 KB
最終ジャッジ日時 2025-01-16 22:06:50
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 78 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main(){
  ll n; cin >> n;  int ans = -1;
  if(n==2){
    cout << 3 << endl; return 0;
  }
  for(int i=2; i<=1000001; i++){
    ll now = n; set<ll> keta;
    while(now>0){
      keta.insert(now%i); now/=i;
    }
    if(keta.size()==1){
      ans = i; break;
    }
  }
  if(ans!=-1){
    cout << ans << endl; return 0;
  }
  for(ll i=1000000; i>=1; i--){
    if(n%i==0 && i<n/i){
      ans = n/i - 1; break;
    }
  }
  cout << ans << endl;
}
  
  
0