You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Farrukh Ahmad edited this page Dec 30, 2015
·
1 revision
A number we n may call Happy Prime if
"n is called prime happy if there is at least one prime less than n and the sum of all primes less
than n is evenly divisible by n."
For example
25 is Happy Prime because 2, 3, 5, 7, 11, 13, 17, 19, 23 are the primes less than 25, their sum is 100 and 25
evenly divides 100
public class HappyPrime {
public static void main(String[] args) {
int n=25;
System.out.println(isHappyPrime(n));
}
static boolean isHappyPrime(int n){
if(n==2) return false;
int sum = 0;
for(int i=0; i<n; i++){
if(isPrime(i))
sum+=i;
}
System.out.println(sum);
return sum % n == 0;
}
static boolean isPrime(int n)
{
if(n==0 || n==1) return false;
if(n==2) return true;
for(int i=2; i<n; i++)
{
if( n%i == 0 ) return false;
}
return true;
}
}