CSU1162-Balls in the Boxes-快速幂、数论
2017-06-26 00:14
405 查看
Q: Balls in the Boxes
Description
Mr. Mindless has many balls and many boxes,he wants to put all the balls into some of the boxes.Now, he wants to know how many different solutions he can have.you know,he could put all the balls in one box,and there could be no balls in some of the boxes.Now,he tells you the number of balls and the numbers of boxes, can you to tell him the number of different solutions? Because the number is so large, you can just tell him the solutions mod by a given number C.
Both of boxes and balls are all different.
Input
There are multiple testcases. In each test case, there is one line cantains three integers:the number of boxes ,the number of balls,and the given number C separated by a single space.All the numbers in the input are bigger than 0 and less than 2^63.Output
For each testcase,output an integer,denotes the number you will tell Mr. MindlessSample Input
3 2 4 4 3 5
Sample Output
1 4
其实结果就是a^b%c
推理网上找找,我也是看着才懂的
模板+1
#include <bits/stdc++.h> #define N 10100 #define INF 0x3f3f3f3f #define LL long long #define ULL unsigned long long #define mem(a,n) memset(a,n,sizeof(a)) #define fread freopen("in.txt","r",stdin) #define fwrite freopen("out.txt","w",stdout) #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; ULL MultiMod(ULL a,ULL b,ULL mod) { ULL res=0; while(b){ if(b&1){ res=(res+a)%mod; b-=1; }else{ a=(a+a)%mod; b>>=1; } } return res; } ULL PowMod(ULL a,ULL b,ULL mod) { ULL res=1; while(b){ if(b&1){ res=MultiMod(res,a,mod); b-=1; }else{ a=MultiMod(a,a,mod); b>>=1; } } return res; } int main() { ios::sync_with_stdio(false); ULL a,b,c; while(cin>>a>>b>>c){ cout<<PowMod(a,b,c)<<endl; } return 0; } /********************************************************************** Problem: 1162 User: CSUzick Language: C++ Result: AC Time:24 ms Memory:1688 kb **********************************************************************/
相关文章推荐
- CSU 1162 Balls in the Boxes 快速幂 水
- CSUOJ 1162 Balls in the Boxes 快速幂
- Balls in the Boxes
- poj 3696 The Luckiest number——数论 (快速幂取模,乘法取模模版)
- poj 2388 Who's in the Middle(快速排序求中位数)
- 快速多尺度人脸检测2--Multi-Scale Fully Convolutional Network for Face Detection in the Wild
- Which is the fastest way to draw the screen in Symbian?---Symbian中最快速屏幕绘画的两种方法
- Codeforces - 385E. 4000 Bear in the Field - 矩阵快速幂
- poj 2388 Who's in the Middle(快速排序求中位数)
- HDU 1157 Who's in the Middle (快速排序 or 任意排序)
- HDU 1157(Who's in the Middle) 快速排序
- Codeforeces Round #226 (Div. 2) E---Bear in the Field(矩阵快速幂)
- Codeforces #284 div1 D. Traffic Jams in the Land 数论 线段树
- PowerShell to Create New Mailboxes in the smallest database in Exchange 2007 Organization
- POJ 2388 Who's in the Middle (快速选择算法:O(N)求数列第K大)
- VK Cup 2015 - Finals, online mirror F. Clique in the Divisibility Graph 数论
- 【hdu2462】【数论】【欧拉函数+欧拉定理+大数快速幂】The Luckiest number
- POJ 2388 Who's in the Middle (快速选择算法:O(N)求数列第K大)
- 快速排序浅谈——(解题报告)HDU1157和POJ2388---Who's in the Middle
- Lightinthebox模版快速修改