結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
tarattata1
|
| 提出日時 | 2019-06-29 11:53:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,253 bytes |
| コンパイル時間 | 650 ms |
| コンパイル使用メモリ | 74,816 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-07-02 05:29:54 |
| 合計ジャッジ時間 | 4,045 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 TLE * 1 |
| other | -- * 42 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:46:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | 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;
void preparePrime( int maxp )
{
int i;
vector<int> a(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.001;
for(i=2; i<=lim; i++) {
int k = i*i;
for(j=0; j<(int)pp.size(); j++) {
int val=k-pp[j];
if(val<2) break;
if (find(pp.begin(), pp.end(), val)!=pp.end()) {
cnt++;
}
}
}
printf("%d\n", cnt);
return 0;
}
tarattata1