why 5 RA?

P5719 【深基4.例3】分类平均

51zzZ @ 2023-03-24 09:34:52

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] num = new int[n];
        double total = 0;
        double size = 0;
        for (int i = 1; i <= n; i++){
            if (i % k == 0){
               num[i-1] = i;
            }
        }
        for (int i = 0; i < n; i++){
            if (num[i] != 0){
                total += num[i];
                size++;
            }
        }
        System.out.printf("%.1f ",total/size);
        System.out.printf("%.1f",(5050-total)/(n-size));
    }
}

|