提出 #41162530
ソースコード 拡げる
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
using ll = long long;
const double pi = 3.14159265359;
const ll INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b){ if (a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if (a < b){a = b; return true;} return false;}
//using mint = modint998244353;
//using mint = modint1000000007;
//using mint = modint; // mint::set_mod(p); later
//using mint = static_modint<1000000009>;
void solve()
{
ll N;
cin >> N;
// b^d <= を満たす最大の b
set<ll> ds;
ds.insert(2);
ds.insert(N);
if (N >= 3) ds.insert(N - 1);
int len = 1;
while ((1LL << len) <= N){ len++; }
for (int d = 3; d <= len ; d++){
ll ok = 1;
ll ng = (ll) 2e9;
while (abs(ok - ng) > 1){
ll mid = (ok + ng) / 2;
__uint128_t x = 1;
for (int i = 0; i < d - 1; i++){
x *= mid;
if (x > N) break;
}
if (x <= N) ok = mid;
else ng = mid;
}
if (ok > 2) ds.insert(ok);
}
ll ans = 0;
for (ll d : ds){
if (d == 2 || d == N || d == N - 1){
ans++;
continue;
}
bool ok = true;
ll x = N;
while (x > 0){
if (x % d > 1){
ok = false;
break;
}
x /= d;
}
if (ok) ans++;
}
cout << ans << "\n";
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T;
cin >> T;
for (int i = 0; i < T; i++){
solve();
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Zero or One |
| ユーザ | unnohideyuki |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 500 |
| コード長 | 1606 Byte |
| 結果 | AC |
| 実行時間 | 45 ms |
| メモリ | 3628 KiB |
コンパイルエラー
./Main.cpp: In function ‘void solve()’:
./Main.cpp:40:8: warning: comparison of integer expressions of different signedness: ‘__int128 unsigned’ and ‘ll’ {aka ‘long long int’} [-Wsign-compare]
40 | if (x > N) break;
| ~~^~~
./Main.cpp:42:13: warning: comparison of integer expressions of different signedness: ‘__int128 unsigned’ and ‘ll’ {aka ‘long long int’} [-Wsign-compare]
42 | if (x <= N) ok = mid;
| ~~^~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, example0.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 9 ms | 3620 KiB |
| 001.txt | AC | 45 ms | 3520 KiB |
| 002.txt | AC | 45 ms | 3612 KiB |
| 003.txt | AC | 44 ms | 3552 KiB |
| 004.txt | AC | 34 ms | 3560 KiB |
| 005.txt | AC | 36 ms | 3516 KiB |
| 006.txt | AC | 37 ms | 3628 KiB |
| 007.txt | AC | 24 ms | 3608 KiB |
| 008.txt | AC | 17 ms | 3608 KiB |
| 009.txt | AC | 24 ms | 3520 KiB |
| 010.txt | AC | 16 ms | 3624 KiB |
| 011.txt | AC | 44 ms | 3520 KiB |
| 012.txt | AC | 44 ms | 3556 KiB |
| 013.txt | AC | 44 ms | 3552 KiB |
| 014.txt | AC | 43 ms | 3516 KiB |
| 015.txt | AC | 45 ms | 3584 KiB |
| 016.txt | AC | 43 ms | 3568 KiB |
| 017.txt | AC | 44 ms | 3520 KiB |
| 018.txt | AC | 44 ms | 3532 KiB |
| 019.txt | AC | 45 ms | 3556 KiB |
| 020.txt | AC | 45 ms | 3520 KiB |
| 021.txt | AC | 20 ms | 3520 KiB |
| 022.txt | AC | 16 ms | 3552 KiB |
| 023.txt | AC | 21 ms | 3612 KiB |
| 024.txt | AC | 16 ms | 3616 KiB |
| 025.txt | AC | 15 ms | 3532 KiB |
| 026.txt | AC | 15 ms | 3580 KiB |
| 027.txt | AC | 17 ms | 3520 KiB |
| 028.txt | AC | 15 ms | 3584 KiB |
| 029.txt | AC | 16 ms | 3520 KiB |
| 030.txt | AC | 21 ms | 3552 KiB |
| 031.txt | AC | 43 ms | 3524 KiB |
| 032.txt | AC | 44 ms | 3628 KiB |
| 033.txt | AC | 25 ms | 3520 KiB |
| example0.txt | AC | 2 ms | 3596 KiB |