結果
| 問題 |
No.1312 Snake Eyes
|
| コンテスト | |
| ユーザー |
kyoprouno
|
| 提出日時 | 2020-12-11 21:21:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 118 ms / 2,000 ms |
| コード長 | 2,171 bytes |
| コンパイル時間 | 1,832 ms |
| コンパイル使用メモリ | 183,084 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-30 13:06:41 |
| 合計ジャッジ時間 | 6,483 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 85 |
ソースコード
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
using namespace std;
inline int topbit(unsigned long long x){
return x?63-__builtin_clzll(x):-1;
}
inline int popcount(unsigned long long x){
return __builtin_popcountll(x);
}
inline int parity(unsigned long long x){//popcount%2
return __builtin_parity(x);
}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const ll INF=1e9+7;
int main(){
ll n;
cin >> n;
if(n==1){
cout << 2 << endl;
return 0;
}
if(n==2){
cout << 3 << endl;
return 0;
}
for(ll p=2;p<=min(1000000LL,n);p++){
vector<ll> b;
b.push_back(1);
ll val=p;
ll s=n;
while(val<=n){
b.push_back(val);
val*=p;
}
reverse(b.begin(),b.end());
ll sz=b.size();
ll r=0;
bool ok=true;
rep(i,sz){
if(i){
if(r!=s/b[i]){
ok=false;
break;
}
else{
s-=r*b[i];
}
}
else{
r=s/b[i];
s-=r*b[i];
}
}
if(ok){
cout << p << endl;
return 0;
}
}
vector<ll> q;
for(ll i=1;i*i<=n;i++){
if(n%i==0){
q.push_back(i);
if(i*i!=n){
q.push_back(n/i);
}
}
}
sort(q.rbegin(),q.rend());
for(auto a:q){
ll x=n/a-1;
if(a<x){
cout << x << endl;
return 0;
}
}
cout << n-1 << endl;
return 0;
}
kyoprouno