Blue Bridge Cup: Coprime Number and Its Definition

topic

[Problem description] What
   is the number of positive integers not exceeding 19000 that are relatively prime to 19000?
[Answer Submission]
   This is a question that fills in the blanks with the result, you only need to calculate the result and submit it. The result of this question is an integer. Only fill in this integer when submitting the answer. If you fill in the extra content, you will not be able to score.

answer

   7200

Coprime number definition

  Coprime numbers refer to non-zero natural numbers with two or more integers whose common factor is only 1, and two non-zero natural numbers whose common factor is only 1. 1 is relatively prime to any number

Problem solving ideas

  The factors of 19000 are 2, 5, and 19. If a number is not 0 in% of 2, 5, and 19, it means that the number is relatively prime to 19000.

Code

public class Main {
    
    //蓝桥杯要求class命名为Main,且无package
    public static void main(String[] args) {
    
    
        int count=0;
        for(int i=1;i<=19000;i++){
    
    
            if(i%2==0||i%5==0||i%19==0){
    
     
                continue;
            }
            count++;
        }
        System.out.println(count);
    }
}

Guess you like

Origin blog.csdn.net/qq_47168235/article/details/108911084