File tree Expand file tree Collapse file tree 6 files changed +18
-74
lines changed
Expand file tree Collapse file tree 6 files changed +18
-74
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Problem Link:
3+ #############################################
4+ Author: Siddharth Mishra
5+ GitHub: https://github.com/Hard-Coder05
6+ #############################################
7+ */
18#include < bits/stdc++.h>
29#define endl " \n "
310#define max (a, b ) (a < b ? b : a)
@@ -9,43 +16,17 @@ using namespace std;
916using i64 = long long ;
1017using u64 = unsigned long long ;
1118using u32 = unsigned ;
12- const int d=1000000 ;
13- vector<int > v;
14- int arr[d+5 ];
15- bool prime[d + 5 ];
16- void calc (int n)
17- {
18-
19- memset (prime, true , sizeof (prime));
20-
21- for (int p = 2 ; p * p <= n; p++)
22- {
23- if (prime[p] == true )
24- {
25- for (int i = p * p; i <= n; i += p)
26- prime[i] = false ;
27- }
28- }
29- for (int i=5 ;i<=d;i++){
30- arr[i]=arr[i-1 ];
31- if (prime[i]&&prime[i-2 ]){
32- arr[i]++;
33- }
34- }
35- }
3619int main () {
3720 FIO;
3821#ifndef ONLINE_JUDGE
3922 freopen (" input.txt" , " r" , stdin);
4023 freopen (" output.txt" , " w" , stdout);
4124#endif
42- calc (d);
4325 int tc;
4426 cin >> tc;
4527 while (tc--) {
4628 int n;
47- cin>>n;
48- cout<<arr[n]<<" \n " ;
49-
29+ cin >> n;
30+ cout<<n;
5031 }
51- }
32+ }
Original file line number Diff line number Diff line change 1- /*
1+ /*
22Problem Link:
33#############################################
44Author: Siddharth Mishra
Original file line number Diff line number Diff line change @@ -16,22 +16,6 @@ using namespace std;
1616using i64 = long long ;
1717using u64 = unsigned long long ;
1818using u32 = unsigned ;
19- vector<int > v;
20- void calc (int n){
21- int i, j, flag;
22- for (i = 2 ; i <= n; i++) {
23- flag = 1 ;
24-
25- for (j = 2 ; j <= i / 2 ; ++j) {
26- if (i % j == 0 ) {
27- flag = 0 ;
28- break ;
29- }
30- }
31- if (flag == 1 )
32- v.push_back (i);
33- }
34- }
3519int main () {
3620 FIO;
3721#ifndef ONLINE_JUDGE
@@ -40,24 +24,9 @@ int main() {
4024#endif
4125 int tc;
4226 cin >> tc;
43- vector<int > t;
44- int max=0 ;
4527 while (tc--) {
4628 int n;
47- cin>>n;
48- if (n>max)
49- max=n;
50- t.push_back (n);
51- }
52- calc (max);
53- for (auto i:t){
54- int count=0 ;
55- for (int a=1 ;a<v.size ();a++){
56- if (v[a]>i)
57- break ;
58- if (v[a]-v[a-1 ]==2 )
59- count++;
29+ cin >> n;
30+ cout<<n;
6031 }
61- cout<<count<<endl;
62- }
63- }
32+ }
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 1- 2
2- 11
3- 13
Original file line number Diff line number Diff line change 1- 2
2- 3
You can’t perform that action at this time.
0 commit comments