View Code of Problem 120

#include<iostream>
#include<string>
#include<cstring>
#include<math.h>
#include<algorithm>
using namespace std;
int isprime(int x){
	int flag=0;
	if(x==0||x==1)return 0;
	for(int i=2;i<=x/2;i++){
		if(x%i==0){
			flag=1;
			return 0;
		}
	}
	if(flag==0)return 1;
}

int main(){
	
	char a,b;
	int t1,t2,t3,t4;
	while(cin>>t1>>a>>t2){
		int k=0,s1,s2;
		cin>>t3>>b>>t4;
		s1=t1*2500+t2;
		s2=t3*2500+t4;
//		cout<<s1<<" "<<s2<<endl;
		if(a>b)swap(a,b);
		for(int i=s1;i<=s2;i++){
			if(isprime(i)==1){
				k++;
			}
		}
		cout<<k<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 120