A Meera number is a number such that the number of nontrivial factors is a factor of the number.
Meera number:
6is a Meera number because6has two nontrivial factors :2and3. (A nontrivial factor is a factor other than1and the number). Thus6has two nontrivial factors. Now,2is a factor of6. Thus the number of nontrivial factors is a factor of6. Hence6is a Meera number.30is a Meera number because30has2, 3, 5, 6, 10, 15as nontrivial factors. Thus30has6nontrivial factors. Note that6is a factor of30. So30is a Meera Number.
Not Meera number:
21is not a Meera number. The nontrivial factors of21are3and7. Thus the number of nontrivial factors is2. Note that2is not a factor of21. Therefore,21is not a Meera number.
Write a function named isMeera that:
- returns
1if its integer argument is a Meera number - otherwise it returns
0
The signature of the function is int isMeera(int n)
public class Assignment73 {
public static void main(String[] args) {
int result = isMeera(6);
System.out.println(result);
result = isMeera(30);
System.out.println(result);
result = isMeera(21);
System.out.println(result);
}
static int isMeera(int n) {
int meeraCount = 0;
for (int i = 2; i < n; i++) {
if (n % i == 0) {
meeraCount++;
}
}
if (n % meeraCount == 0) {
return 1;
}
return 0;
}
}