結果
問題 | No.1514 Squared Matching |
ユーザー | milanis48663220 |
提出日時 | 2021-05-21 22:00:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 365 ms / 4,000 ms |
コード長 | 1,337 bytes |
コンパイル時間 | 2,041 ms |
コンパイル使用メモリ | 114,524 KB |
最終ジャッジ日時 | 2025-01-21 15:12:02 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#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; }