ACM 快速幂模板
原题:
HDU4365
//快速幂模板:
lint quick(lint base, lint pow)
{
lint ret=1;
while(pow)
{
if (pow&1) ret=(ret*base)%mod;
base=(base*base)%mod;
pow>>=1;
}
return ret%mod;//记得最后mod,比如mod==1的情况
}
原题:
题解:http://www.cnblogs.com/bo-tao/archive/2012/08/15/2640380.html
/*
* Author: NICK WONG
* Created Time: 2015/8/5 21:27:00
* File Name: e.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
#define out(x) cout<<#x<<": "<<x<<endl
const double eps(1e-8);
const int maxn=10100;
const long long maxint=-1u>>1;
const long long maxlong=maxint*maxint;
typedef long long lint;
set<pair<int, int> > s;
int n,m;
lint k;
const long long mod=100000007;
void init()
{
}
void change(int& x, int& y)
{
if (x>n/2) x=n+1-x;
if (y>n/2) y=n+1-y;
if (x>y) swap(x,y);
}
lint quick(lint base, lint pow)
{
lint ret=1;
while(pow)
{
if (pow&1) ret=(ret*base)%mod;
base=(base*base)%mod;
pow>>=1;
}
return ret;
}
void work()
{
lint ans=0;
s.clear();
for (int i=1; i<=(n+1)/2; i++)
ans+=i;
for (int i=1; i<=m; i++)
{
int x,y;
cin>>x>>y;
x++; y++;
change(x,y);
s.insert(make_pair(x,y));
}
ans-=s.size();
ans=quick(k,ans);
cout<<ans<<endl;
}
int main()
{
while(cin>>n>>m>>k)
{
init();
work();
}
return 0;
}
Description
In addition fond of programing, Jack also loves painting. He likes to draw many interesting graphics on the paper.
One day,Jack found a new interesting graph called Palindrome graph. No matter how many times to flip or rotate 90 degrees, the palindrome graph are always unchanged.
Jack took a paper with n*n grid and K kinds of pigments.Some of the grid has been filled with color and can not be modified.Jack want to know:how many ways can he paint a palindrome graph?
One day,Jack found a new interesting graph called Palindrome graph. No matter how many times to flip or rotate 90 degrees, the palindrome graph are always unchanged.
Jack took a paper with n*n grid and K kinds of pigments.Some of the grid has been filled with color and can not be modified.Jack want to know:how many ways can he paint a palindrome graph?
Input
There are several test cases.
For each test case,there are three integer n m k(0<n<=10000,0<=m<=2000,0<k<=1000000), indicate n*n grid and k kinds of pigments.
Then follow m lines,for each line,there are 2 integer i,j.indicated that grid(i,j) (0<=i,j<n) has been filled with color.
You can suppose that jack have at least one way to paint a palindrome graph.
For each test case,there are three integer n m k(0<n<=10000,0<=m<=2000,0<k<=1000000), indicate n*n grid and k kinds of pigments.
Then follow m lines,for each line,there are 2 integer i,j.indicated that grid(i,j) (0<=i,j<n) has been filled with color.
You can suppose that jack have at least one way to paint a palindrome graph.
Output
For each case,print a integer in a line,indicate the number of ways jack can paint. The result can be very large, so print the result modulo 100 000 007.
Sample Input
3 0 2 4 2 3 1 1 3 1
Sample Output
8 3