HDU 1812 polya 大数

由于反射的存在,分奇偶讨论其置换的循环节数量,大数用JAVA就好了。

 

import java.math.*;
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n, t;
        while(cin.hasNext()) {
            n = cin.nextInt();
            BigInteger c = cin.nextBigInteger();
            BigInteger sum = BigInteger.valueOf(0);
            if(n % 2 == 0)    {
                sum = sum.add(c.pow(n * n));//0
                sum = sum.add(c.pow(n * n / 4));//90
                sum = sum.add(c.pow(n * n / 2));//180
                sum = sum.add(c.pow(n * n / 4));//270
                sum = sum.add(c.pow(n * (n - 1) / 2 + n));//mirC
                sum = sum.add(c.pow(n * (n - 1) / 2 + n));//mirC
                sum = sum.add(c.pow(n * n / 2));//mirM
                sum = sum.add(c.pow(n * n / 2));//mirM
            }
            else{
                sum = sum.add(c.pow(n * n));//0
                sum = sum.add(c.pow((n * n - 1) / 4 + 1));//90
                sum = sum.add(c.pow((n * n - 1) / 2 + 1));//180
                sum = sum.add(c.pow((n * n - 1) / 4 + 1));//270
                sum = sum.add(c.pow(n * (n + 1) / 2));//mirC
                sum = sum.add(c.pow(n * (n + 1) / 2));//mirC
                sum = sum.add(c.pow(n * (n + 1) / 2));//mirM
                sum = sum.add(c.pow(n * (n + 1) / 2));//mirM
            }
            sum = sum.divide(BigInteger.valueOf(8));
            System.out.println(sum);
            
        }
    }
}
posted @ 2017-09-19 20:46  Lweleth  阅读(280)  评论(0编辑  收藏  举报