n=1  --> ans = 2 = 1*2 = 2^0(2^0+1) n=2  -->  ans = 6 = 2*3 = 2^1(2^1+1) n=3  -->  ans = 20 = 4*5 = 2^2(2^2+1) n=4  -->  ans = 72 = 8*9 = 2^3(2^3+1) n=k  -->  ??? = 2^k-1*(2^k-1+1) 于是题目转化为快速幂求模问题..... #include<bits/stdc++.h> using nam…
$A(x)=1+x^2/2!+x^4/4!...$ $A(x)=1+x^1/1!+x^2/2!...$ 然后把生成函数弄出来. 暴力手算. 发现结论. 直接是$4^{n-1}+2^{n-1}$ 然后快速幂. #include <map> #include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1097 分析:简单题,快速幂取模, 由于只要求输出最后一位,所以开始就可以直接mod10. /*A hard puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 33036 Accepted Submission(s): 11821 Pr…
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.Each…
这种有限制的类棋盘着色问题一般可以用指数型母函数来解决,设Hn表示这样的着色数,首先H0=1,则Hn等于四个字母的(A,B,C,D)的多重集合的n排列数,其中每个字母的重数是无穷,且要求A,C出现的次数是偶数,因此,H0,H1,...Hn,...的指数生成函数是A,B,C,D因子的乘积: 用快速幂解决,只不过在HDU不能用long long解决,要用__int64. 代码: #include <iostream> #include <cstdio> #include <cst…
Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8679    Accepted Submission(s): 3525 Problem Description 医学界发现的新病毒因其蔓延速度和Internet上传播的"红色病毒"不相上下,被称为"红色病毒",经研究发现,该病毒及其变种的DNA的一条单链中,胞…
题意:给定一个数,求n^n的个位数. 析:很简单么,不就是快速幂么,取余10,所以不用说了,如果不会快速幂,这个题肯定是周期的, 找一下就OK了. 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring> #include <map> using…
小明的求助 时间限制:2000 ms  |  内存限制:65535 KB 难度:2 描述 小明对数学很有兴趣,今天老师出了道作业题,让他求整数N的后M位,他瞬间感觉老师在作弄他,因为这是so easy! 当他看到第二道题目的时候,他就确定老师在捉弄他了,求出N^P的后M位,因为他不会了.你能帮他吗? 输入 第一行包含一个整数T(T <= 1000),代表测试数据组数. 接下来的T行每行含三个整数,N,P,M(1 <= N <= 10^10,1 <= P <= 10^15,1…
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 39554    Accepted Submission(s): 14930 Problem Description Given a positive integer N, you should output the most right digit of N…
指数型母函数的应用 求A B C D 在规定条件下n个元素的排列个数,先写出指数型母函数 G(X) = ( 1 + x + x^2/2! + x^3/3! +... )^2 * ( 1+ x^2/2! + x^4/! + .. )^2 前者表示:B, D出现方式不限制:后者表示:A, C 只能出现偶数或者不出现情况 又知: e^x=1+x/1!+x^2/2!+x^3/3!+... e^(-x)=1-x/1!+x^2/2!-x^3/3!+... 化简得: G(x)  = e^(2x) * ((e^…