Blue Bridge Simulation Tournament: Inverse multiple test

Problem Description

Given three integers a, b, and c, if an integer is neither an integer multiple of a nor a multiple of b nor an integer multiple of c, then this number is called an inverse multiple.
  How many inverse multiples are there from 1 to n?
Input format
  The first line of input contains an integer n.
  The second line contains three integers a, b, c, separated by a space between two adjacent numbers.
Output format    The
  output line contains an integer that represents the answer.
Sample input
30
2 3 6
Sample output
10
Sample description    The
  following numbers meet the requirements: 1, 5, 7, 11, 13, 17, 19, 23, 25, 29.
Evaluation use case scale and conventions
  For 40% of evaluation use cases, 1 <= n <= 10000.
  For 80% of the test cases, 1 <= n <= 100000.
  For all evaluation cases, 1 <= n <= 1000000, 1 <= a <= n, 1 <= b <= n, 1 <= c <= n.


Code:


import java.util.ArrayList;
import java.util.Scanner;

public class 测数 {
    
    
	public static void main(String[] args) {
    
    
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a=s.nextInt();
		int b=s.nextInt();
		int c=s.nextInt();
		if(n>0&&n<1000001&&a>0&&a<=n&&b>0&&b<=n&&c>0&&c<=n) {
    
    
			ArrayList<Integer> list=new ArrayList<Integer>();
			for(int i=0;i<=n;i++) {
    
    
				if(i%a!=0&&i%b!=0&&i%c!=0) {
    
    
					list.add(i);
				}
			}
			System.out.print(list.size());
		}
	}
}

Guess you like

Origin blog.csdn.net/DAurora/article/details/105655755