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. How to hide an entry in the Add/Remove Programs applet?

    Original link: http://www.winhelponline.com/articles/15/1/How-to-hide-an-entry-in-the-AddRemove-Prog ...

  2. ueditor使用代码高亮的方法

    最近发现ueditor支持代码高亮,但是页面上并没有起效果,于是网上找了下,发现还需做如下修改: 1.页面引用以下资源文件(均位于ueditor目录中): <script type=" ...

  3. Linux 网络I/O模型

    前言 本文是笔者的第一篇博文,在这篇文章的大部分内容基于steven大神的<Unix Network Programming>.一来是对书本内容的整理与归纳.二来也是为接下来的博文奠定基础 ...

  4. sprintf函数php的详细使用方法

    PHP sprintf() 函数 先说下为什么要写这个函数的前言,这个是我在微信二次开发的一个token验证文档也就是示例文档看到的一个函数,当时非常不理解,于是查了百度,但是很多结果都很笼统,结果也 ...

  5. VB6-图像分割利器 Microsoft Picture Clip控件

    在医院做图像处理时碰到双面扫描仪,需要将扫描到的2张图像分割为一张并打印.在分割图像的过程中总是不得法,后来虽然有CBM666的指导,但给的方法也还是不太方便.无意中在翻一本vb书的时候看到了一个使用 ...

  6. TCO 2014 Round 1A

    顺利搞出  A B 两题,然后压线晋级了,手速场. A 题 , 求排列最小的,肯定从后往前来做,维护一个最小的set,只是第一个字母要特判一下. 1: #line 5 "EllysSorti ...

  7. check whether the crystal report runtime is exists 检查crystalreport运行时是否存在

    1. Try Dim rptDoc As New CrystalDecisions.CrystalReports.Engine.ReportClass() Dim rptView As New Cry ...

  8. mysql 的存储引擎

    注意:mysql开发很少显示使用外键,MyISAM可以定义外键,但不起作用. mysql最新的5.6版本支持,全文索引.

  9. 我的PHP之旅--数组的认识(初级)

    数组 PHP的数组与swift有些许不同,分为3类(初级,以后会涉及到多维数组和数组指针等). 枚举数组 关联数组 混合数组 枚举数组 枚举数组跟swift中的数组差不多: <?php $arr ...

  10. iOS8的一些控件的变更---备用

    UISearchDisplayController变更为UISearchController UIAlertView变更为UIAlertController 如果添加点击事件则需要使用UIAlertC ...