結果
| 問題 | No.3388 Sum of Function |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-02 10:28:07 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,047 bytes |
| コンパイル時間 | 3,228 ms |
| コンパイル使用メモリ | 196,696 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-02 10:28:12 |
| 合計ジャッジ時間 | 3,570 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
import std;
void main() {
int a, b;
readf("%d %d\n", a, b);
const p = new PrimeTable(b);
long ret = 0;
foreach(e; p.prime) {
if(e < a) {
continue;
}
ret += f(e);
}
writeln(ret);
}
pragma(inline)
long f(const int x) pure @nogc nothrow @safe {
return x * x * x - x * x + x + 1;
}
class PrimeTable {
private bool[] isPrime;
private int n;
this(const int n) {
this.n = n;
isPrime = new bool[n + 1];
isPrime[] = true;
isPrime[0] = isPrime[1] = false;
foreach(i; 2U..n + 1) {
if(!isPrime[i]) {
continue;
}
foreach(j; iota(i * i, n + 1, i)) {
isPrime[j] = false;
}
}
}
bool[] table() pure nothrow @safe @nogc {
return isPrime;
}
int[] prime() pure const nothrow @safe {
int[] p;
foreach(i; 2..n + 1) {
if(isPrime[i]) {
p ~= i;
}
}
return p;
}
}