結果

問題 No.1514 Squared Matching
ユーザー seiyu_kyoproseiyu_kyopro
提出日時 2021-05-22 00:53:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,310 ms / 4,000 ms
コード長 2,641 bytes
コンパイル時間 3,231 ms
コンパイル使用メモリ 178,472 KB
実行使用メモリ 394,016 KB
最終ジャッジ日時 2024-04-18 17:16:14
合計ジャッジ時間 26,046 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1,298 ms
393,976 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 16 ms
9,228 KB
testcase_07 AC 248 ms
77,924 KB
testcase_08 AC 1,252 ms
379,676 KB
testcase_09 AC 1,063 ms
332,380 KB
testcase_10 AC 1,177 ms
359,796 KB
testcase_11 AC 1,224 ms
374,776 KB
testcase_12 AC 1,263 ms
385,260 KB
testcase_13 AC 1,289 ms
390,192 KB
testcase_14 AC 1,289 ms
392,296 KB
testcase_15 AC 1,278 ms
393,132 KB
testcase_16 AC 1,287 ms
393,580 KB
testcase_17 AC 1,283 ms
393,980 KB
testcase_18 AC 1,297 ms
393,972 KB
testcase_19 AC 1,310 ms
394,016 KB
testcase_20 AC 1,286 ms
393,884 KB
testcase_21 AC 1,296 ms
393,860 KB
testcase_22 AC 232 ms
81,440 KB
testcase_23 AC 475 ms
159,648 KB
testcase_24 AC 730 ms
237,788 KB
testcase_25 AC 1,017 ms
315,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iomanip>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <numeric>
#include <vector>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;

i64 solve(i64 n)
{
    i64 ans = 0;
    vector<i64> prime(7500, true); // 素数かどうか?
    vector<i64> x(n + 1); // 指数が奇数であるものの積
    rep(i, n + 1) x[i] = i;
    i64 i = 2;
    while(i * i <= n)
    {
        if(prime[i])
        {
            i64 w = i * i;
            i64 j = w; 
            while(j * j <= n) // エラストテネスの篩
            {
                prime[j] = false; // 素数でない
                j += i;
            }

            j = w;
            while(j <= n) // p^2, p^4, p^6, ... 
            {
                i64 k = j; // p^2, p^4, ...
                while(k <= n)
                {
                    x[k] /= w;
                    k += j; // p^2 -> 2 * p^2, p^4 -> 2 * p^4, ...
                }
                j *= w;
            }
        }
        i++;
    }
    for (i = 1; i < n + 1; i++)
    {
        ans += sqrt(n / x[i]);
    }
    return ans;
}


int main()
{
    i64 n;
    cin >> n;
    cout << solve(n) << endl;
    return 0;
}
0