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 ...
随机推荐
- RequireJs使用快速入门
前言:Requirejs作为一个ES5环境流行的模块加载器,在很多项目中使用它.而且这个开源库任然在更新,同类产品seajs已经不更新了. ES6之后引入import 或者使用Commonjs的方式引 ...
- angularJS请求参数 ajax
1. 使用angular服务请求 app.controller('main', function($scope, $http) { $scope.fun1 = function () { $http( ...
- swagger2配置和使用
1.导入swagger2 <dependency> <groupId>io.springfox</groupId> <artifactId>spring ...
- POI 2000 ------Stripes
Stripes Time Limit:1000MS Memory Limit:30000KBTotal Submit:94 Accepted:43 Description Stripes is a t ...
- Linux From Scratch(从零开始构建Linux系统,简称LFS)(三)
九. 系统配置 1. 安装 LFS-Bootscripts-20150222 软件包包含一套在 LFS 系统启动和关闭时的启动和停止脚本. cd /sources tar -jxf lfs-boots ...
- sharepint 2013 添加subsite
在用服务器端对象模型往里面添加subsite的时候,照着书上的代码,结果,失败.报错 not suported language. bing了半天,说是语言未支持,又是修改系统区域,显示语言等,还是失 ...
- webpack-loader原理
loader loader 是导出为一个函数的 node 模块.该函数在 loader 转换资源的时候调用.给定的函数将调用 loader API,并通过 this 上下文访问. loader配置 { ...
- Hello Activemq
0. 如果永远是localhost 可能一直low下去 1.下载安装 activemq 1.1 从官网下载activemq.tar.gz 并上传(rz)到linux系统 并解压 tar zxvf /* ...
- 洛谷11月月赛题解(A-C)
心路历程 辣鸡T3卡我1.5h题意,要不是最后nlh跟我解释了一下大样例估计这次是真凉透了.. A P4994 终于结束的起点 打出暴力来发现跑的过最大数据?? 保险起见还是去oeis了一波,然后被告 ...
- layui-学习02-全局样式
CSS内置公共基础类 类名(class) 说明 布局 layui-main 用于设置一个宽度为 1140px 的水平居中块(无响应式) layui-inline 用于将标签设为内联块状元素 layui ...