清华大学 约数的个数

来源:互联网 发布:淘宝零食店铺推荐知乎 编辑:程序博客网 时间:2024/04/28 11:04
import java.util.Scanner;/** * Created by fhqplzj on 17-1-25 at 下午11:06. */public class My2 {    private static int getNum(int n) {        int result = 0;        int i = 1;        for (; i * i < n; i++) {            if (n % i == 0) {                result += 2;            }        }        if (i * i == n) {            result++;        }        return result;    }    public static void main(String[] args) {        Scanner scanner = new Scanner(System.in);        while (scanner.hasNextInt()) {            int n = scanner.nextInt();            if (n == 0) {                break;            }            for (int i = 0; i < n; i++) {                System.out.println(getNum(scanner.nextInt()));            }        }    }}

0 0
原创粉丝点击