[FOJ 1752] A^B mod C
Accept: 750 Submit: 3205
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63).
Input
There are multiply testcases. Each testcase, there is one line contains three integers A, B and C, separated by a single space.
Output
For each testcase, output an integer, denotes the result of A^B mod C.
Sample Input
2 10 1000
Sample Output
24
二分快速幂模板题
#include <iostream>
#include <cstdio>
using namespace std;
#define ll __int64 ll quickadd(ll a,ll b,ll c) //运用快速幂的思想快速加,这样就不会溢出
{
ll ret=;
while(b)
{
if(b&)
{
ret+=a;
if(ret>=c) ret-=c; //这样比直接取模(ret%=c)更快
}
a<<=;
if(a>=c) a-=c;
b>>=;
}
return ret;
}
ll quickpow(ll a,ll b,ll c)
{
ll ret=;
while(b)
{
if(b&) ret=quickadd(a,ret,c);
a=quickadd(a,a,c);
b>>=;
}
return ret;
}
int main()
{
ll a,b,c;
while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
{
printf("%I64d\n",quickpow(a%c,b,c));
}
return ;
}
[FOJ 1752] A^B mod C的更多相关文章
- 福州大学oj 1752 A^B mod C ===>数论的基本功。位运用。五星*****
Problem 1752 A^B mod C Accept: 579 Submit: 2598Time Limit: 1000 mSec Memory Limit : 32768 KB P ...
- FZU 1650 1752 a^b mod c
http://acm.fzu.edu.cn/problem.php?pid=1752 http://acm.fzu.edu.cn/problem.php?pid=1650 给跪了. 我的快速幂会越界. ...
- FZU 1752 A^B mod C(快速加、快速幂)
题目链接: 传送门 A^B mod C Time Limit: 1000MS Memory Limit: 65536K 思路 快速加和快速幂同时运用,在快速加的时候由于取模耗费不少时间TLE了 ...
- FOJ ——Problem 1759 Super A^B mod C
Problem 1759 Super A^B mod C Accept: 1368 Submit: 4639Time Limit: 1000 mSec Memory Limit : 32 ...
- Problem 2020 组合(FOJ)
Problem 2020 组合 Accept: 714 Submit: 1724Time Limit: 1000 mSec Memory Limit : 32768 KB Problem ...
- 函数mod(a,m)
Matlab中的函数mod(a,m)的作用: 取余数 例如: mod(25,5)=0; mod(25,10)=5; 仅此.
- ORACLE 数据库 MOD 函数用法
1.求2和1的余数. Select mod(2,1) from dual: 2能被1整除所以余数为0. 2.MOD(x,y)返回X除以Y的余数.如果Y是0,则返回X的值. Select mod(2,0 ...
- 黑科技项目:英雄无敌III Mod <<Fallen Angel>>介绍
英雄无敌三简介(Heroes of Might and Magic III) 英3是1999年由New World Computing在Windows平台上开发的回合制策略魔幻游戏,其出版商是3DO. ...
- [日常训练]mod
Description 给定$p_1,p_2,-,p_n,b_1,b_2,...,b_m$, 求满足$x\;mod\;p_1\;\equiv\;a_1,x\;mod\;p_2\;\equiv\;a_2 ...
随机推荐
- sublime 安装 Terminal 使用 cmder
在 packagecontrol.io 可以找到 Terminal. 在 cmder.net 下载 cmder 复制 Terminal.sublime-settings 文件到 C:\Users\WX ...
- C# 调用load事件
在一个函数或者事件中调用另外的事件,例如调用Load事件 private void EventForm_Load(object sender, EventArgs e) { //相关内容 } priv ...
- jQuery—一些常见方法(2)DOM操作【insertBefore(),insertAfter(),appendTo(),prependTo(),before(),after(),append(),prepend(),remove(),on(),off(),scrollTop()】
一.insertBefore() 如下代码:找到span标签,将span标签剪切到div的前面 <!DOCTYPE html> <html lang="en"&g ...
- Eat that Frog
Eat that Frog,中文翻译过来就是“吃掉那只青蛙”.不过这里并不是讨论怎么去吃青蛙,而是一种高效的方法. Eat that Frog是Brian Tracy写的一本书(推荐阅读).这是一个很 ...
- JS访问Struts 2 ValueStack中的内容
/* * var myArray = new Array("${vacant[0]}", "${vacant[1]}", "${vacant[2]}& ...
- css3太极图效果+自动旋转
主要使用border-radius属性实现圆,半圆,定位坐标覆盖部分模块. 半圆: width: 50%; height: 100%; border-radius:100% 0 0 100% /50% ...
- MySQL基础学习之视图
创建新的视图 CREATE VIEW 视图名 AS SELECT 属性,属性1,属性2 FROM 表名 创建新的视图并指定数据名 CREATE VIEW 视图名(新属性,新属性1,新属性2) ...
- Pycharm使用技巧
1.代码配色,即主题 pycharm自带的配色方案都很难看,网上的配色方案又很难看,所以根据其他ide的Monokai配色方案,自己定义了一个. pycharm Monokai主题下载:http:// ...
- ASP.NET 学习小记 -- “迷你”MVC实现(2)
Controller的激活 ASP.NET MVC的URL路由系统通过注册的路由表对HTTO请求进行解析从而得到一个用户封装路由数据的RouteData对象,而这个过程是通过自定义的UrlRoutin ...
- UILocalNotification本地通知
// 执行通知一定要退出应用或挂起应用(进入后台)才能收到通知. 1.在iOS8及其以后版本中使用本地消息需要先获得用户的许可,否则无法成功注册本地消息.因此,我们将询问用户许可的代码片段添加到了ap ...