結果

問題 No.1514 Squared Matching
ユーザー Be11T_Be11T_
提出日時 2021-05-21 23:09:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,028 bytes
コンパイル時間 4,476 ms
コンパイル使用メモリ 259,164 KB
実行使用メモリ 220,760 KB
最終ジャッジ日時 2024-04-18 16:43:42
合計ジャッジ時間 13,440 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,693 ms
220,760 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, m, n) for(ll i = m; i <= n; i++)
#define rrep(i, m, n) for(ll i = m; i >= n; i--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define SZ(a) ((ll)(a).size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, 1, -1 };
const int inf = 1e9 + 1;
const ll INF = 1e18 + 1;
const double pi = acos(-1);

using Graph = vector < vector <ll >>;

//typedef atcoder::modint1000000007 mint;
//typedef atcoder::modint998244353 mint;
//typedef modint mint_b;
const int MAX_N = 50000010;
vector<int> prime; // i.th prime
vector<int> first_prime(MAX_N + 1); // その数を最初に割り切る素数を格納 i = first_prime[i]ならiは素数(i≧2)

void sieve() {
    for (int i = 0; i <= MAX_N; i++) first_prime[i] = 1;
    first_prime[0] = first_prime[1] = 1;
    for (int i = 2; i <= MAX_N; i++) {
        if (first_prime[i] == 1) {
            prime.push_back(i);
            for (int j = i; j <= MAX_N; j += i) first_prime[j] = i;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n; cin >> n;
    sieve();
    ll res = 0;

    for(int i = 1; i <= n; i++) {
        map<int, int> mp;
        int m = i;
        while (m > 1) {
            mp[first_prime[m]]++;
            m /= first_prime[m];
        }
        int cur = 1;
        for (auto v : mp) {
            if (v.second % 2 == 1) cur *= v.first;
        }
        int x = i / cur;
        int le = 1, ri = i + 1;
        while (ri - le >= 1) {
            int mid = (le + ri) / 2;

            if (mid * mid <= x) {
                le = mid + 1;
            }
            else {
                ri = mid;
            }
        }

        res += (le - 1) * 2 - 1;
    }
    cout << res << endl;
}
0