結果
| 問題 |
No.407 鴨等素数間隔列の数え上げ
|
| コンテスト | |
| ユーザー |
mudbdb
|
| 提出日時 | 2016-08-06 00:18:19 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 46 ms / 1,000 ms |
| コード長 | 578 bytes |
| コンパイル時間 | 432 ms |
| コンパイル使用メモリ | 21,888 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2024-12-15 22:33:57 |
| 合計ジャッジ時間 | 1,335 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 31 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:21:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%d %d",&N,&L);
| ^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdlib.h>
char *P = 0;
int Pr(int n) {
P = (char*)malloc(sizeof(char)*(n+1));
int i;
int j;
for (i=0; i<=n; i++) P[i] = 1;
P[0] = 0;
P[1] = 0;
for (i=2; i<=n; i++) {
if (P[i] == 1) {
for (j=i*2; j<=n; j+=i) {
P[j] = 0;
}
}
}
}
int main() {
int N,L;
scanf("%d %d",&N,&L);
int i;
long long int M = 0;
if (2 <= L/(N-1)) {
M += (L - 2*(N-1) + 1);
}
Pr(L/(N-1));
for (i=3; i<=L/(N-1); i+=2) {
if (P[i] == 1) {
M += (L - i*(N-1) + 1);
}
}
printf("%lld\n",M);
return 0;
}
mudbdb