i want u to act as the most skilled competetive programmer, u take time to think and…
- User
i want u to act as the most skilled competetive programmer, u take time to think and check if ur solution works and match up with the example tescase, u need to think thoroughly since u r in a contest. use need to use this template, make sure u have lowercase rlly short variable names and NO COMMENTS (in the code, at all) and since ur using this template always use int and not long long, PLS REVALUATE UR CODE AND MAKE SURE IT MAKES SURE IT MATCHES EVERY SINGLE SAMPLE INPUT AND OUTPUT GIVEN, THINK MULTIPLE TIMES BEFORE GIVING UR FINAL ANSWER AS THIS IS A CONTEST: #include <bits/stdc++.h> #define int long long using namespace std;
signed main() { cin.tie(0); ios_base::sync_with_stdio(false); }
A positive integer is an N N-subtractorization if it is a prime number that can be expressed as the difference of two primes that are both at most N N. For example, the complete set of 5 5-subtractorizations is { 2 , 3 } {2,3} because 5 − 3
2 5−3=2 and 5 − 2
3 5−2=3. For a given N N, how many N N-subtractorizations are there? Constraints 1 ≤ T ≤ 100 1≤T≤100 1 ≤ N ≤ 10 , 000 , 000 1≤N≤10,000,000 Input Format Input begins with an integer T T, the number of test cases. Each case is a single line that contains the integer N N. Output Format For the i ith test case, print "Case #i: " followed by a single integer, the number of N N-subtractorizations. Sample Explanation The first case is explained above. In the second case, the complete set of 8 8-subtractorizations is { 2 , 3 , 5 } {2,3,5}. Sample Input 2 5 8 Sample Output Case #1: 2 Cas
- Assistant
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int T; cin>>T; const int MAX=10000000; vector<char> sieve(MAX+1,1); sieve[0]=sieve[1]=0; for(int i=2;i*i<=MAX;i++) if(sieve[i]){ for(int j=i*i;j<=MAX;j+=i) sieve[j]=0; } vector<int> primes; for(int i=2;i<=MAX;i++) if(sieve[i]) primes.push_back(i); for(int tc=1;tc<=T;tc++){ int n; cin>>n; int cnt=0; for(auto p: primes){ if(p>n) break; if(p==2){ cnt++; continue; } bool found=0; for(auto q: primes){ if(q > n - p) break; if(sieve[p+q]){ cnt++; found=1; break; } } } cout<<"Case #"<<tc<<": "<<cnt<<"\n"; } }