Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- //#define max_index 1000001
- // The code doesn't run for above value of Max_index
- // But is accepted in Geeks For Geeks
- #define max_index 100000
- // But Runs fine for this value
- using namespace std;
- int main(){
- long long int prime[max_index], i, j;
- prime[0] = 0;
- for(i = 1; i < max_index; i++){
- prime[i] = i;
- }
- for(i = 2; i < max_index; i++){
- for(j = i + i; j < max_index; j += i){
- if(prime[j] % i == 0) prime[j] = 0;
- }
- }
- // Showing the list of Prime numbers
- /*
- for(i = 1; i < max_index; i++){
- if(prime[i] != 0) cout << prime[i] << ' ';
- }
- cout << endl;
- */
- int t; cin >> t;
- while(t--){
- int n; cin >> n;
- int result = 0, k = 2;
- while(prime[k] <= n){
- result += prime[k++];
- }
- cout << result << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement