-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem 27.cpp
More file actions
66 lines (63 loc) · 1.26 KB
/
Problem 27.cpp
File metadata and controls
66 lines (63 loc) · 1.26 KB
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
59
60
61
62
63
64
65
66
//ANSWER IS -59231
//EXECUTION PROCESS MIGTH TAKE SOME TIME
#include<iostream>
using namespace std;
int prime(int b)
{
if(b<0)
b*=-1;
int flag=0;
for(int i=2;i<=b/2;i++)
{
if(b%i==0)
{
flag=1;
break;
}
}
if(flag==1)
return 0;
else
return 1;
}
long isprime(int a,int b)
{ //cout<<"\t\tas\n";
int flag=0;
long long num;
long n=1;
while(flag==0)
{
num=(n*n)+(a*n)+b;
if(prime(num)==0||num<0)
break;
n++;
// cout<<n<<"\t";
}
return n;
}
int main()
{
int a=999,b=1000;
long max=1,num;
int ma,mb;
while(a>-1000)
{ cout<<"\n"<<a<<" "<<b<<" "<<max<<"\n";
if(prime(b)==1)
{ // cout<<"\n112";
num=isprime(a,b);
if(num>max)
{
max=num;
ma=a;
mb=b;
}
}
b--;
if(b==-1)
{
a--;
b=1000;
}
}
cout<<max<<" "<<ma<<" "<<mb<<" "<<ma*mb;
}