Lanqiao Cup official website fill-in-the-blank question (lucky number)

Question description

This question is a fill-in-the-blank question. You only need to calculate the result and use the output statement in the code to output the filled-in result.

Tourists traveling to Planet X are issued an integer as a tourist number.

The King of Planet X has a quirk. He only likes the numbers 3, 5 and 7.

The king stipulated that if the visitor's number only contains factors: 3, 5, 7, he can get a prize.

Let’s look at the top 10 lucky numbers:

3579152125273545

So the 11th lucky number is: 49

Xiao Ming received a lucky number 59084709587505. When he went to receive the prize, he was asked to accurately tell which lucky number it was, otherwise he would not receive the prize.

Please help Xiao Ming calculate which lucky number is 59084709587505.

operating restrictions

  • Maximum running time: 1s
  • Maximum running memory: 128M
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        long n=59084709587505L;
        int ans=0;
        for(int i=0;Math.pow(3,i)<n;i++){
          for(int j=0;Math.pow(5,j)<n;j++){
            for(int k=0;Math.pow(7,k)<n;k++){
              if(Math.pow(3,i)*Math.pow(5,j)*Math.pow(7,k)<n){
                ans++;
              }
            }
          }
        }
        System.out.println(ans);
    }
}

Guess you like

Origin blog.csdn.net/s44Sc21/article/details/132797737