I have a problem to check if the total score is equal to any coefficient of the number. I am participating in the JAVA Programming training phase. The question is this:
*
The Bishal number is such a number that the number of non-trivial factors is a factor of the number. For example, 6 is the Bishal number, because 6 has two non-trivial factors: 2 and 3. (A factor other than 1 and a number is a non-trivial factor). Thus, 6 has two non-trivial factors. Now, 2 is a factor of 6. Thus, the number of non-trivial factors is a factor of 6. Therefore, 6 is the Bishal number. Another Bishal number - 30 30 has 2, 3, 5, 6, 10, 15 as non-trivial factors. Thus, 30 has 6 non-trivial factors. Note that 6 is a factor of 30. Thus, 30 is the Bishal Number. However, 21 is not a Bishal number. Non-trivial factors 21 are equal to 3 and 7. Thus, the number of non-trivial factors is 2. Note that 2 is not a factor of 21. Therefore, 21 is not a Bishal number.Write an isBishal function that returns 1 if its integer argument is Bishal, otherwise it will return 0.
Function Signature is int isBishal (int n)
*
I can create a function. But I do not understand how to check the total with factors. Some parts of my solution correspond to the following:
public static int isBishal(int n){
int count=0;
for (int i=2; i<n; i++){
double result=(double)n/i;
if(result==Math.ceil(result)){
int factor=(int) result;
count++;
}
}
Where can I compare the final score (i.e. the total number of factors) with any factor? If I use a coefficient equal to the counter, the count starts with 1,2,3 and so on. And that can compare the score of 1, 2,3 or so with factors. I need to compare Final count. I set the score from the cycle. But then the factor scale is only in the if condition. You cannot compare the outer loop.
Someone please let me understand this program .PS: This program is not complete because I can not compare.
source
share