FZU-1759 Super A^B mod C---欧拉降幂&指数循环节
题目链接:
https://cn.vjudge.net/problem/FZU-1759
题目大意:
求A^B%C

解题思路:

注意,这里long long需要用%I64读入,不能用%lld
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 2e6 + ;
int euler_phi(int n)//求单个
{
int m = (int)sqrt(n + 0.5);
int ans = n;
for(int i = ; i <= m; i++)if(n % i == )
{
ans = ans / i * (i - );
while(n % i == )n /= i;
}
if(n > )ans = ans / n * (n - );
return ans;
}
ll mul(ll a, ll b, ll m)
//求a*b%m
{
ll ans = ;
a %= m;
while(b)
{
if(b & )ans = (ans + a) % m;
b /= ;
a = (a + a) % m;
}
return ans;
}
ll pow(ll a, ll b, ll m)
{
ll ans = ;
a %= m;
while(b)
{
if(b & )ans = mul(a, ans, m);
b /= ;
a = mul(a, a, m);
}
ans %= m;
return ans;
}
ll super_pow(ll a, char b[], ll c)
{
ll t = euler_phi(c), n = strlen(b), tot = ;
for(int i = ; i < n; i++)
{
tot = tot * + b[i] - '';
tot %= t;
}
tot += t;
return pow(a, tot, c);
}
char b[maxn];
int main()
{
ll a, c;
while(~scanf("%I64d%s%I64d", &a, b, &c))
{
printf("%I64d\n", super_pow(a, b, c));
}
return ;
}
FZU-1759 Super A^B mod C---欧拉降幂&指数循环节的更多相关文章
- HDU - 5728:PowMod (欧拉函数&指数循环节)
Declare: k=∑ m i=1 φ(i∗n) mod 1000000007 k=∑i=1mφ(i∗n) mod 1000000007 n n is a square-free number. φ ...
- FZU 1759 Super A^B mod C 指数循环节
Problem 1759 Super A^B mod C Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description G ...
- FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时 ...
- 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 ...
- fzou 1759 Super A^B mod C
Problem 1759 Super A^B mod CAccept: 456 Submit: 1488Time Limit: 1000 mSec Memory Limit : 32768 ...
- FZU 1759 题解 欧拉降幂
本题考点:欧拉降幂 Super A^B mod C Given A,B,C, You should quickly calculate the result of A^B mod C. (1<= ...
- FZU1759(SummerTrainingDay04-B 欧拉降幂公式)
Problem 1759 Super A^B mod C Accept: 1056 Submit: 3444Time Limit: 1000 mSec Memory Limit : 327 ...
- 【转】【关于 A^x = A^(x % Phi(C) + Phi(C)) (mod C) 的若干证明】【指数循环节】
[关于 A^x = A^(x % Phi(C) + Phi(C)) (mod C) 的若干证明][指数循环节] 原文地址:http://hi.baidu.com/aekdycoin/item/e493 ...
- hdu4549 矩阵快速幂 + 欧拉降幂
R - M斐波那契数列 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
随机推荐
- FocusBI:SSAS体系结构(原创)
关注微信公众号:FocusBI 查看更多文章:加QQ群:808774277 获取学习资料和一起探讨问题. SSAS是微软BI组件系列中最核心的组件,商业智能的心脏所有的数据都从这里统一输出,它能把 ...
- mysql之调优概论
一 简介 咱们先不说cpu的频率,内存的大小(这个和索引一样重要,但不是本文讨论的内容),硬盘的寻道时间.想起mysql的调优,最起码的必须知道explain执行计划,慢sql日志,老旧的profi ...
- 异步http请求的实现
这是我自己在某论坛上发的一篇水贴:http://www.sufeinet.com/thread-9275-1-2.html,原理和解释,我就直接重发一遍在自己博客上了. 时隔一个月 回来把之前的坑填 ...
- golang学习之win7下go环境搭建
以下均采用windows64环境,首先是go的下载,go有msi安装安装和zip解压安装两种安装方式,使用msi安装后go环境会自动配置,zip解压后需手动配置各种环境变量. 首先是下载,网上一搜一大 ...
- Charles破解(转)
NB的Charles是一款付费软件.但…本文将讲解如何破解Charles.注:虽然与文章内容相悖,但还是希望大家能购买正版软件,毕竟都是做软件开发的,何必自断生路,要有版权意识. 环境信息: Mac ...
- [android] 实现返回键操作思路
记录用户点击的操作历史,使用栈数据结构,频繁的操作栈顶(添加,获取,删除),使用LinkedList 捕获用户的返回键操作,响应返回键,返回上一个界面 MainActivity.java /** * ...
- 紫书第5章 C++STL
例题 例题5-1 大理石在哪儿(Where is the Marble?,Uva 10474) 主要是熟悉一下sort和lower_bound的用法 关于lower_bound: http://blo ...
- docker 容器中设置 mysql lampp php软链接
在容器中安装xampp后,进入到终端,直接输入mysql php 发现报错,命令未被发现.如果输入/opt/lampp/bin/mysql 就可以进入了,所以我们要找到在容器中安装的位置,然后将他 ...
- Python基础-月考
1. 8<<2等于? # 解释:将8按位左移2位 # 8 0 0 0 0 1 0 0 0 # 32 0 0 1 0 0 0 0 0 2. 通过内置函数计算5除以2的余数 print(div ...
- C++ VS编译问题--VS下生成DLL,但没有生成Lib的解决办法
如果项目生成了.dll文件,但是没有生成.lib文件,这是由于项目的设置错误,应作如下修改: 项目->属性->链接器->输入->模块定义文件,设置你的模块定义文件,默认为lib ...