1 / 2
Mar 2020


My code give TLE.

#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int countPrime(int val1,int val2){
    int flag ;
     if (val1==1 )
        val1+=1;
     if (val1==2){
        cout << val1  <<endl;
         
        }
    if(val1 &0)
    val1+=1;

    for(int i = val1;i<=val2;i+=2){
        
        if (i%2==0)
        i++;
        
        flag  = 0;
       
        for(int j = 2;j<i/2;j++){
            
            if(i%j == 0){
            flag = 1;
            break;
            }
        }
        if(flag == 0)
        cout << i << endl;;
    }
}
int main(){
    int n,m,i,x,y;
   vector<int> x1,x2;
   vector<int>::iterator ptr1,ptr2;
   cin >> n;
   m = n;
   while(n!=0){
       cin >> x >> y;
       x1.push_back(x);
       x2.push_back(y);
       n--;
   }
   for(int i = 0;i<m;i++){
       countPrime(x1[i],x2[i]);
       cout << " " << endl;
   }
   return 0;
}
  • created

    Mar '20
  • last reply

    Mar '20
  • 1

    reply

  • 489

    views

  • 2

    users

  • 2

    links

Suggested Topics

Topic Category Replies Views Activity
Online Judge System 0 102 Apr 14

Want to read more? Browse other topics in Online Judge System or view latest topics.