牛牛做水题Java解
牛牛做水题
https://ac.nowcoder.com/acm/contest/10322/A
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 返回牛牛获得的快乐指数 * @param n int整型 题单里的题目数量 * @return int整型 */ public int solve (int n) { //快乐分数 int happyScore = 0; final int LEVEL = 2; List<Integer> numberList = new LinkedList<Integer>(); for (int number = 1; number <= n; number++) { numberList.add(number); } for (final int number: numberList) { int sum = 0; for (int i = 1; i <= number; i++) { if(number%i == 0) { sum += i; } } if(sum/number < LEVEL) { happyScore += number; } } return happyScore; } public static void main(String[] args) { Solution solution = new Solution(); System.out.println(solution.solve(282)); } }