-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem50.cpp
71 lines (60 loc) · 1.36 KB
/
Problem50.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
59
60
61
62
63
64
65
66
67
68
69
70
71
//997651
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int lenOfLongSubarr(ll arr[], ll n, ll k)
{
unordered_map<ll, ll> um;
ll sum = 0, maxLen = 0;
for (ll i = 0; i < n; i++) {
sum += arr[i];
if (sum == k)
maxLen = i + 1;
if (um.find(sum) == um.end())
um[sum] = i;
if (um.find(sum - k) != um.end()) {
if (maxLen < (i - um[sum - k]))
maxLen = i - um[sum - k];
}
}
return maxLen;
}
bool isprime(ll num)
{
for(int i=2;i<=sqrt(num);i++)
{
if(num%i==0)
return false;
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ll prime[100000];
ll index = 0;
prime[index++]=2;
prime[index++]=3;
ll maxval1 = 0;
ll maxval2 = 0;
for(int i=5;i<1000000;i+=2)
{
if(isprime(i))
{
cout<<i<<"\n";
prime[index++] = i;
ll val1 = lenOfLongSubarr(prime,index-1,i);
if(val1>maxval1)
{
maxval1 = val1;
maxval2 = i;
}
}
}
cout<<maxval2<<"\n";
}