hdu 3547 DIY Cube (Ploya定理)
来源:互联网 发布:linux终端粘贴快捷键 编辑:程序博客网 时间:2024/06/07 03:33
DIY Cube
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 584 Accepted Submission(s): 284
Problem Description
Mr. D is interesting in combinatorial enumeration. Now he want to find out the number of ways on painting the vertexes of a cube. Suppose there are C different colors and two paintings are considered the same if they can transform from one to another by rotation.
Input
There are multiple test cases in the input, the first line of input contains an integer denoting the number of test cases.
For each test case, there are only one integer C, denoting the number of colors. (1 <= C <= 1000000000)
For each test case, there are only one integer C, denoting the number of colors. (1 <= C <= 1000000000)
Output
For each test case, output the the number of painting ways. And if the number is equal or larger than 1015, output the last 15 digits.
Sample Input
312112
Sample Output
Case 1: 1Case 2: 23Case 3: 031651434916928
/* * 题意:用n中颜色涂一个正方体的八个顶点,求有多少种方法。如果得到的结果大于等于10^15,则输出后15位即可。思路:Ploya定理啊,是组合数学课本上的原题。对应于四种不同类型的旋转,1:不动,即恒等旋转有1个;2:绕三对对立面的中心旋转,有旋转90度,旋转180度,旋转270度,分别有3个;3:绕对边终点连线旋转,有6个;4:绕对角点旋转,有旋转120度和旋转240度,分别有4个。因此共有24个对称。最后可以转化成公式(k^8 + 17*k^4 + 6 * k^2)/ 24 。由于涉及到了大数,所以这道题我使用java写的,刚学java。看着大神的分析,写了写试试,java单词好多, */
import java.util.*;import java.math.*;import java.math.BigInteger;public class Main {public static void main(String[] args){int i,j;BigInteger sum,k,temp;temp= new BigInteger ("1000000000000000");Scanner in=new Scanner(System.in);int t=in.nextInt();for(i=1;i<=t;i++){sum= BigInteger.ZERO;k=in.nextBigInteger();sum=sum.add(k.pow(8));sum=sum.add(k.pow(4).multiply(BigInteger.valueOf(17)));sum=sum.add(k.pow(2).multiply(BigInteger.valueOf(6)));sum=sum.divide(BigInteger.valueOf(24));System.out.print("Case "+i+": ");if(sum.compareTo(temp) > 0){sum= sum.mod(temp);for(j=sum.toString().length(); j<15;j++){System.out.print(0);}}System.out.println(sum);}}}
0 0
- hdu 3547 DIY Cube (Ploya定理)
- HDU 3547 DIY Cube Ploya定理
- HDU 3547 DIY Cube 数论- Polya定理
- hdu 3547 DIY Cube
- hdu 3547 DIY Cube
- HDU 3923 Ploya定理
- hdu 3547 DIY Cube【polya】
- HDOJ 3547 DIY Cube
- POJ 2409 ploya定理
- poj 2154 Color(欧拉函数模板+ploya定理)
- POJ 2154 Color Ploya定理
- HDU 6202 cube cube cube(暴力)
- nyoj-Color the necklace(Ploya定理 + 欧拉函数 + 扩展欧几里得(求逆元))
- nyoj-Color the necklace(Ploya定理 + 欧拉函数 + 扩展欧几里得(求逆元))
- POJ 1286 Necklace of Beads Ploya定理
- ploya定理 学习总结#by nobody
- hdu 6202 cube cube cube
- HDU 2865 Birthday Toy(ploya好题)
- cocos2d-x 3.6版连连看版本控制
- 从主机端能够连接到虚拟机里面的shadowsocks代理么???
- nyoj 70 阶乘因式分解(二)
- Activity四种启动模式
- 批量删除git分支
- hdu 3547 DIY Cube (Ploya定理)
- 关于Activity一些技巧
- 开始刷leetcode day38: Longest Substring Without Repeating Characters
- O(n)回文子串算法
- css transfotm(变化)
- Activity
- 【Android】android图片轮播
- 球中的initVertex
- Python sys.argv的用法