-
Notifications
You must be signed in to change notification settings - Fork 0
/
quadratic-primes.cpp
59 lines (54 loc) · 1.37 KB
/
quadratic-primes.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// https://www.hackerrank.com/contests/projecteuler/challenges/euler027/problem
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
ll N;
cin >>N;
ll prime[1000001] = {0};
prime[0] = true;
prime[1] = true;
for(ll i = 2; i* i <= 1000000;i++)
{
if(!prime[i])
{
for(ll j= i * i ; j <= 1000000; j+=i)
prime[j] = true;
}
}
ll t;
ll ans = 0;
ll temp , temp1;
for( ll j = N; j >=2 ; j--)
{
if(!prime[j])
{
t = j;
for(ll i = -t ; i <= t ; i ++)
{
ll y = t;
ll n = 1;
ll count = 0;
while(!prime[abs(y)])
{
// cout << y << endl;
count ++;
y = n * n + i* n + t;
n++;
}
// if( i == 1)
// cout << i << " " << count << endl;
if(count > ans)
{
ans = count;
temp = i ;
temp1 = t;
}
}
//cout << ans << " " << j <<endl;
}
}
cout << temp << " " << temp1 << endl;
return 0;
}