Problem 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

3 2 4
2 10 1000

 Sample Output

1
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的更多相关文章

  1. 福州大学oj 1752 A^B mod C ===>数论的基本功。位运用。五星*****

    Problem 1752 A^B mod C Accept: 579    Submit: 2598Time Limit: 1000 mSec    Memory Limit : 32768 KB P ...

  2. 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 给跪了. 我的快速幂会越界. ...

  3. FZU 1752 A^B mod C(快速加、快速幂)

    题目链接: 传送门 A^B mod C Time Limit: 1000MS     Memory Limit: 65536K 思路 快速加和快速幂同时运用,在快速加的时候由于取模耗费不少时间TLE了 ...

  4. 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 ...

  5. Problem 2020 组合(FOJ)

    Problem 2020 组合 Accept: 714    Submit: 1724Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem ...

  6. 函数mod(a,m)

    Matlab中的函数mod(a,m)的作用: 取余数 例如: mod(25,5)=0; mod(25,10)=5; 仅此.

  7. 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 ...

  8. 黑科技项目:英雄无敌III Mod <<Fallen Angel>>介绍

    英雄无敌三简介(Heroes of Might and Magic III) 英3是1999年由New World Computing在Windows平台上开发的回合制策略魔幻游戏,其出版商是3DO. ...

  9. [日常训练]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 ...

随机推荐

  1. android开发 单击按钮 实现页面间的跳转

    我的MainActivity.java部分代码 public class MainActivity extends ActionBarActivity { //不要定义button类型,会出错 Vie ...

  2. QT宏 Q_OBJECT,explicit, QHostAddress, quint, emit

    QT相關 一. 參考: 1.宏Q_OBJECT 二. explicit struct constrcution 三. QHostAddress Detailed Description: The QH ...

  3. C++输入结束

    通过判断输入是否等于EOF,可以结束输入. EOF 是个宏,其意思是:End Of File,文件尾标志. 从数值上来看,就是整数-1. 在C语言的头文件中对其进行了宏定义: libio.h:     ...

  4. OpenJudge 2737 大整数除法

    链接地址:http://bailian.openjudge.cn/practice/2737/ 题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 求2个大的正整数相除的商 输入 第 ...

  5. 2D游戏模型中动态分层的处理 及解决方案 (适用于 webgame 手游等资源控制较严格类型)

    文章若非特别注明转载,皆是原创,转载请注明出处. 本文地址:http://www.cnblogs.com/bobolive/p/3537215.html 2D游戏中模型一般都有换装逻辑,特别是联网游戏 ...

  6. 在Mac OS X中搭建STM32开发环境(1)

    本文原创于http://www.cnblogs.com/humaoxiao,非法转载者请自重! 本文方法必须好用!绝不坑爹!看了N多英文资料才搞明白的,适用于STM32F4DISCOVERY评估板,带 ...

  7. day19 数据库的初步认识

    一:数据库的概念 数据库:一个用于储存数据并可以对之进行管理和使用的软件系统. sql:struct(结构)  query(查询)  language(语言) 结构化查询语言: 其实是一种国际化语言标 ...

  8. ado.net中的几个对象

    Connection:用于连接数据源 Command:对数据源执行命令 DataReader:在只读和只写的连接模式下从数据源读取数据. DataAdpter:从数据源读取数据并使用所读取的数据填充数 ...

  9. linux环境下验证码不显示的几种情况

    linux环境下验证码不显示的几种情况 gd库扩展没有安装. 查看phpinfo(),看看有没有安装gd库 yum安装gd库或者phpize安装 安装完成后记得重启php-fpm bom头的原因 在生 ...

  10. Xcode 7.3.1的模拟器路径

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Core ...