19000 100000

* this program accept two integers and output the number of primes number between them ( inclusive the begin and end number ) and also show the number of primes number which be able to write as the result of 2 squsred number p = c^2 + b^2 , the program stopped when inter -1 -1 as input

# include <iostream> # include < math.h> using namespace std; bool func( int num) { bool square= false; int sum1=-1, sum2=-1; float number = num; float temp1; int temp2; while ( number !=1) { temp1=sqrt(number); temp2= (int)temp1; if (temp1-temp2==0) { sum1=sqrt(number); number =num-(sum1*sum1); temp1=sqrt(number); temp2= (int)temp1; if (temp1-temp2==0) { sum2=sqrt(number); square= true; break; } number= sum1*sum1; } number--; } return square; } bool IsPrime(int num) { bool prime = true; if ( num<= 1) return false; for ( int i=2; i<num;i++) if ( num%i== 0 ) prime =false; return prime; } int main() { int first_Num, last_Num,Total_primes=0,NUm_primes_has_squares=0; bool change = false; cin >> first_Num >> last_Num; while ( first_Num!=-1 || last_Num!=-1) { if ( first_Num ==last_Num) { change = true; last_Num++; } for ( int i=first_Num; i<=last_Num;i++) { if ( IsPrime(i)) { Total_primes++; if ( func(i)) NUm_primes_has_squares++; } } if ( change) last_Num--; cout << first_Num << " " << last_Num<<" "<<Total_primes <<" " <<NUm_primes_has_squares<<endl; cin >> first_Num >> last_Num; Total_primes=0; NUm_primes_has_squares=0; } return 0; }

This post has been edited by **daliash**: 15 August 2009 - 08:18 AM