結果

問題 No.1514 Squared Matching
ユーザー shift_atcshift_atc
提出日時 2021-06-17 08:01:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,524 ms / 4,000 ms
コード長 1,977 bytes
コンパイル時間 2,545 ms
コンパイル使用メモリ 187,956 KB
実行使用メモリ 198,468 KB
最終ジャッジ日時 2023-08-30 16:39:04
合計ジャッジ時間 29,020 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1,524 ms
198,288 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 20 ms
6,100 KB
testcase_07 AC 271 ms
40,412 KB
testcase_08 AC 1,447 ms
191,404 KB
testcase_09 AC 1,272 ms
167,672 KB
testcase_10 AC 1,378 ms
181,260 KB
testcase_11 AC 1,430 ms
188,852 KB
testcase_12 AC 1,471 ms
193,952 KB
testcase_13 AC 1,478 ms
196,516 KB
testcase_14 AC 1,508 ms
197,640 KB
testcase_15 AC 1,502 ms
198,140 KB
testcase_16 AC 1,510 ms
198,332 KB
testcase_17 AC 1,504 ms
198,336 KB
testcase_18 AC 1,500 ms
198,280 KB
testcase_19 AC 1,499 ms
198,288 KB
testcase_20 AC 1,501 ms
198,468 KB
testcase_21 AC 1,510 ms
198,340 KB
testcase_22 AC 287 ms
42,268 KB
testcase_23 AC 601 ms
80,988 KB
testcase_24 AC 900 ms
120,420 KB
testcase_25 AC 1,212 ms
159,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = INT_MAX / 2;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n + 1);
    iota(all(v), 0);
    for (ll i = 2; i * i <= n; i++)
    {
        ll k = i * i;
        while (k <= n)
        {
            for (int j = 0; j <= n; j += k)
            {
                if (v[j] % k == 0 && v[j] % (k * i * i) != 0)
                    v[j] /= k;
            }
            k *= i * i;
        }
    }


    int ans = 0;
    for (int a = 1; a <= n; a++)
    {
        int s = v[a];
        int k = (sqrt(n) / sqrt(s)) - 1;
        while (s * (k + 1) * (k + 1) <= n)
        {
            k++;
        }
        ans += k;
    }
    cout << ans << endl;
    return 0;
}
0