Trang

Chủ Nhật, 2 tháng 1, 2011

1154. A Mathematical Curiosity

import java.io.*;

public class Main {

    /**
     * http://acm.tju.edu.cn/toj/showp1154.html
     * @author hunglee
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {

        StreamTokenizer in = new StreamTokenizer(new BufferedReader(
                new InputStreamReader(System.in)));
        
        int n, m, t = 0;
        do {
            in.nextToken();
            n = (int) in.nval;
            in.nextToken();
            m = (int) in.nval;
            if (n == 0 && m == 0) break;
            
            int res = 0;
            for (int a = 1; a < n - 1; ++a)
                for (int b = a + 1; b < n; ++b)
                    if ((a * a + b * b + m) % (a * b) == 0) ++ res;
            ++t;
            System.out.println("Case " + t + ": " + res);
            
        } while (true);
    }

}

Không có nhận xét nào:

Đăng nhận xét