---
title: "快速幂取模"
author: "SwordAndFlame"
date: "2011-08-21T22:48:32Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-08-21T22:48:32Z"
id: 1154614
url: "https://swordandflame.iteye.com/blog/1154614"
---

```
lld exp_mod(lld a,lld b,lld c)
{
    lld ans=1;
    lld temp=a%c;
    if(b==0)    return 1;
    while(b)
    {
        if(b&1) ans=ans*temp%c;
        temp=temp*temp%c;
        b>>=1;
    }
    return ans;
}
```