結果
| 問題 |
No.3156 Count That Day's N
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-23 19:39:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 3,000 ms |
| コード長 | 4,147 bytes |
| コンパイル時間 | 2,380 ms |
| コンパイル使用メモリ | 204,968 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-05-23 19:39:13 |
| 合計ジャッジ時間 | 3,542 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double PI = acos(-1.0);
#define sqr(x) ((ll)(x) * (x))
#define ff first
#define ss second
#define pb push_back
#define srt(v) sort(v.begin(), v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define rvrs(v) reverse(v.begin(), v.end())
#define yes printf("YES\n")
#define no printf("NO\n")
#define pf1(a) printf("%lld", a)
#define pf2(a, b) printf("%lld %lld", a, b)
#define case(a) printf("Case %lld: ", a)
#define ses printf("\n")
#define CC(x) cout << "Case #" << ++x << ":";
#define LL_INF (1LL << 62)
#define INF (1 << 30)
#define SetBit(x, k) (x = (1LL << k))
#define ClearBit(x, k) (x &= ~(1LL << k))
#define CheckBit(x, k) ((x >> k) & 1)
void substring(string s, int i, string cur)
{
if (i == s.size())
{
cout << cur << endl;
return;
}
substring(s, i + 1, cur + s[i]);
substring(s, i + 1, cur);
}
ll ch2digit(char s)
{
char charvalue = s;
ll number = (int(charvalue) + 0);
return number - 97;
}
long long Sqrt(long long x)
{
long long l = 1, r = 1e9, ans = 0;
while (l <= r)
{
long long mid = (l + r) >> 1;
if (mid * mid <= x)
{
ans = mid;
l = mid + 1;
}
else
{
r = mid - 1;
}
}
return ans;
}
void permutaion(string s, int l, int r)
{
if (l == r)
{
cout << s << endl;
return;
}
for (int i = l; i <= r; i++)
{
swap(s[l], s[i]);
permutaion(s, l + 1, r);
swap(s[l], s[i]);
}
}
bool pallindrome(string s, int l, int r)
{
if (l >= r)
return true;
if (s[l] != s[r])
return false;
return pallindrome(s, l + 1, r - 1);
}
char int2char(int N)
{
return char(N);
}
void numToBinRepresentation(ll n)
{
for (ll i = 15; i >= 0; --i)
{
// ll x = ((n>>i)&1);
cout << ((n >> i) & 1);
}
cout << endl;
}
const ll P = 31;
const ll MOD = 1e9 + 9;
// Compute power of P
vector<ll> computePowers(int n) {
vector<ll> power(n);
power[0] = 1;
for (int i = 1; i < n; ++i)
power[i] = (power[i - 1] * P) % MOD;
return power;
}
// Compute prefix hash
vector<ll> computePrefixHash(const string &s, const vector<ll>& power) {
int n = s.size();
vector<ll> hash(n);
hash[0] = (s[0] - 'a' + 1);
for (int i = 1; i < n; ++i) {
hash[i] = (hash[i - 1] + (s[i] - 'a' + 1) * power[i]) % MOD;
}
return hash;
}
// Get hash of substring [l, r]
ll getSubHash(const vector<ll> &hash, const vector<ll> &power, int l, int r) {
ll result = hash[r];
if (l > 0) result = (result - hash[l - 1] + MOD) % MOD;
return (result * power[power.size() - 1 - l]) % MOD; // Normalize
}
bool isPalindrome(const string &s) {
string rev = s;
reverse(rev.begin(), rev.end());
int n = s.size();
auto power = computePowers(n + 1);
auto hash1 = computePrefixHash(s, power);
auto hash2 = computePrefixHash(rev, power);
// Compare full normalized hashes
ll hash_original = getSubHash(hash1, power, 0, n - 1);
ll hash_reverse = getSubHash(hash2, power, 0, n - 1);
return hash_original == hash_reverse;
}
bool isPerfectSquare(ll n) {
ll x = sqrt(n);
return x * x == n;
}
void solve()
{
ll k, n;
cin >> k >> n;
unordered_set<ll> goodNumbers;
ll maxX = pow(n, 1.0 / 6) + 1;
ll maxY = pow(n, 1.0 / 4) + 1;
for (ll x = 1; x <= maxX; x++) {
ll x6 = 1;
for (int i = 0; i < 6; ++i) x6 *= x;
if (x6 > n) break;
for (ll y = 1; y <= maxY; y++) {
ll y4 = 1;
for (int i = 0; i < 4; ++i) y4 *= y;
ll rhs = x6 + y4;
if (rhs > n) break;
if (rhs % k != 0) continue;
ll lhs = rhs / k;
if (isPerfectSquare(lhs)) {
goodNumbers.insert(rhs);
}
}
}
cout << goodNumbers.size() << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
ll t = 1;
//cin >> t;
while (t--)
{
solve();
}
}