結果

問題 No.1514 Squared Matching
ユーザー milanis48663220milanis48663220
提出日時 2021-05-21 22:00:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 504 ms / 4,000 ms
コード長 1,337 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 118,364 KB
実行使用メモリ 247,808 KB
最終ジャッジ日時 2024-04-18 15:27:42
合計ジャッジ時間 12,067 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 209 ms
247,552 KB
testcase_01 AC 414 ms
247,680 KB
testcase_02 AC 223 ms
247,808 KB
testcase_03 AC 233 ms
247,680 KB
testcase_04 AC 218 ms
247,684 KB
testcase_05 AC 242 ms
247,552 KB
testcase_06 AC 255 ms
247,684 KB
testcase_07 AC 283 ms
247,680 KB
testcase_08 AC 421 ms
247,808 KB
testcase_09 AC 374 ms
247,684 KB
testcase_10 AC 504 ms
247,680 KB
testcase_11 AC 399 ms
247,680 KB
testcase_12 AC 409 ms
247,808 KB
testcase_13 AC 469 ms
247,552 KB
testcase_14 AC 399 ms
247,692 KB
testcase_15 AC 430 ms
247,684 KB
testcase_16 AC 431 ms
247,688 KB
testcase_17 AC 427 ms
247,688 KB
testcase_18 AC 419 ms
247,808 KB
testcase_19 AC 446 ms
247,552 KB
testcase_20 AC 411 ms
247,680 KB
testcase_21 AC 423 ms
247,680 KB
testcase_22 AC 280 ms
247,552 KB
testcase_23 AC 323 ms
247,808 KB
testcase_24 AC 351 ms
247,680 KB
testcase_25 AC 376 ms
247,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;
using P = pair<int, int>;
map<P, ll> memo;
bool sq[50000001];
int cnt[50000001];

void init(){
    for(int i = 2; i*i <= 50000000; i++){
        int m = i*i;
        for(int j = 1; j*m <= 50000000; j++){
            sq[j*m] = true;
        }
    }
    for(int i = 1; i <= 50000000; i++) cnt[i] = cnt[i-1] + (sq[i] ? 1 : 0);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    int n; cin >> n;
    ll ans = 0;
    for(int a = 1; a*a <= n; a++){
        for(int b = 1; b*b <= n; b++){
            int p = n/(a*a);
            int q = n/(b*b);
            ans += min(p, q)-cnt[min(p, q)];
        }
    }
    cout << ans << endl;
}
0