結果
問題 | No.1312 Snake Eyes |
ユーザー |
![]() |
提出日時 | 2020-12-09 01:13:42 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 1,011 bytes |
コンパイル時間 | 2,020 ms |
コンパイル使用メモリ | 191,564 KB |
最終ジャッジ日時 | 2025-01-16 20:21:39 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 85 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;template<class T> using vec = vector<T>;template<class T> using vvec = vector<vec<T>>;template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}#define all(x) (x).begin(),(x).end()#define debug(x) cerr << #x << " = " << (x) << endl;int main(){cin.tie(0);ios::sync_with_stdio(false);ll N;cin >> N;if(N==1){cout << 2 << "\n";return 0;}ll ans = N+1;if(N>2) ans = N-1;for(ll i=2;i*i<=N;i++){ll a = i;while(a<=N){a *= i;ll now = (a-1)/(i-1);if(now>N) break;if(now>0 && N%now==0 && N/now<i) chmin(ans,i);}if(N%i==0){ll n = N/i;if(n<i-1) chmin(ans,i-1);n = i;if(n<N/i-1) chmin(ans,N/i-1);}}cout << ans << "\n";}