Codeforces Round #319 (Div. 2) A. Multiplication Table

原题: http://codeforces.com/contest/577/problem/A


题目大意: 给两个数字,n和k, 找出等于k的个数在n*n的table中, table中每一位是i*j, where i and j are row and column


分析: 这个暴不了, 所以考的是观察. 观察题中给的example:

我们可以发现, 在一个n=6的表中, k=12 出现在6 4 3 2. 这些数字都是12的除数, 可是少了几个啊, 12本身也是除数,1 也是除数, 而且在n=10,k=5中, 我们发现答案是2(1和5). 那么上边的1和12 为什么不算? 因为 12/1 = 12 , 12不在表中. 所以我们得到另一个条件, 除完的余数要小于等于n.

public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int k = in.readInt();
            int count = 0;
            for (int i = 1; i <= n; i++) {
                if (k % i == 0 && k / i <= n)
                    count++;
            }
            out.print(count);
        }