結果
| 問題 |
No.152 貯金箱の消失
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-19 02:22:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,176 bytes |
| コンパイル時間 | 1,683 ms |
| コンパイル使用メモリ | 159,584 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-12 01:36:35 |
| 合計ジャッジ時間 | 1,868 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int r_max = 2500;
int min_p[r_max + 10];
int use_p[20];
int max_m(int L, int n){
int m = (int)((sqrt(2 * L + 4 * n * n) - 2 * n) / 4) - 2;
m = max(n + 1, m);
while(8 * m * (n + m) <= L)++m;
--m;
return m;
}
int solve(int size, int upper){
if(use_p[0] != 2)upper /= 2;
int res = upper;
for(int mask=1;mask<1<<size;mask++){
int L = 1;
int cnt = 0;
for(int i=0;i<size;i++)if((mask >> i) & 1){
L *= use_p[i];
++cnt;
}
if(cnt % 2 == 1){
res -= upper / L;
} else {
res += upper / L;
}
}
return res;
}
int solve(int L){
int res = max_m(L, 1) / 2;
for(int n=2;8*(n+1)*(2*n+1)<=L;n++){
int size = 0;
use_p[size++] = min_p[n];
int t = n / min_p[n];
while(t > 1){
if(use_p[size-1] != min_p[t]){
use_p[size++] = min_p[t];
}
t /= min_p[t];
}
res += solve(size, max_m(L, n)) - solve(size, n);
}
return (res % 1000003);
}
int main(){
for(int n=2;n<=r_max;n++)min_p[n] = n;
for(int p=2;p*p<=r_max;p++)if(min_p[p] == p){
for(int kp=p*p;kp<=r_max;kp+=p)if(p < min_p[kp]){
min_p[kp] = p;
}
}
int L;
cin >> L;
cout << solve(L) << endl;
return 0;
}