結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
tarattata1
|
| 提出日時 | 2019-06-29 12:15:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,290 bytes |
| コンパイル時間 | 736 ms |
| コンパイル使用メモリ | 74,456 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-02 05:30:09 |
| 合計ジャッジ時間 | 2,395 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 40 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:48:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;
vector<int> pp;
vector<int> a;
void preparePrime( int maxp )
{
int i;
a.resize(maxp+1);
for(i=2; i<=maxp; i++) {
int k=i+i;
while(k<=maxp) {
a[k]=1;
k+=i;
}
}
for(i=2; i<=maxp; i++) {
if(a[i]==0) pp.push_back( i );
}
return;
}
int main(int argc, char* argv[])
{
int n;
scanf("%d", &n);
preparePrime( n );
int cnt=0;
int i, j;
double lim=sqrt((double)n)+0.1;
for(i=2; i<=lim; i++) {
if(a[i]) continue;
int k = i*i;
for(j=0; j<(int)pp.size(); j++) {
int val=k-pp[j];
if(val>n) continue;
if(val<2) break;
if (a[val]==0) {
cnt++;
}
}
}
printf("%d\n", cnt);
return 0;
}
tarattata1