P5091 【模板】欧拉定理

以上3张图是从这篇 博客 里盗的,讲的比较清楚。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=20001006;
ll mod(ll x,ll p)
{
return x>=p?x%p+p:x%p;
}
ll phi(ll x)
{
ll res=x,a=x;
for(ll i=2;i*i<=x;++i)
{
if(a%i==0)
{
res=res/i*(i-1);
while(a%i==0)a/=i;
}
}
if(a>1)res=res/a*(a-1);
return res;
}
ll qpow(ll n,ll k,ll p)
{
ll base=n,res=1;
while(k)
{
if(k&1)res=res*base%p;
base=base*base%p;
k>>=1;
}
return res;
}
ll a,c,p,sum,len;
char b[N];
int main()
{
scanf("%lld%lld%s",&a,&c,b);
len=strlen(b);p=phi(c);sum=0;
for(int i=0;i<len;++i)
sum=mod((b[i]-'0'+sum*10),p);
printf("%lld\n",qpow(a,sum,c));
return 0;
}

P5091 【模板】欧拉定理(欧拉降幂)的更多相关文章

  1. 数学--数论--欧拉降幂--P5091 欧拉定理

    题目背景 出题人也想写有趣的题面,可惜并没有能力. 题目描述 给你三个正整数,a,m,ba,m,ba,m,b,你需要求:ab mod ma^b \bmod mabmodm 输入格式 一行三个整数,a, ...

  2. 2018牛客网暑期ACM多校训练营(第四场) A - Ternary String - [欧拉降幂公式][扩展欧拉定理]

    题目链接:https://www.nowcoder.com/acm/contest/142/A 题目描述 A ternary string is a sequence of digits, where ...

  3. 牛客OI测试赛 F 子序列 组合数学 欧拉降幂公式模板

    链接:https://www.nowcoder.com/acm/contest/181/F来源:牛客网 题目描述 给出一个长度为n的序列,你需要计算出所有长度为k的子序列中,除最大最小数之外所有数的乘 ...

  4. 广义欧拉降幂(欧拉定理)——bzoj3884,fzu1759

    广义欧拉降幂对于狭义欧拉降幂任然适用 https://blog.csdn.net/qq_37632935/article/details/81264965?tdsourcetag=s_pctim_ai ...

  5. FZU 1759 题解 欧拉降幂

    本题考点:欧拉降幂 Super A^B mod C Given A,B,C, You should quickly calculate the result of A^B mod C. (1<= ...

  6. 牛客网多校第4场 A.Ternary String 【欧拉降幂】

    题目:戳这里 学习博客:戳这里 欧拉函数的性质: ① N是不为0的整数.φ(1)=1(唯一和1互质的数就是1本身) ② 除了N=2,φ(N)都是偶数. ③ 小于N且与N互质的所有数的和是φ(n)*n/ ...

  7. hdu4549 矩阵快速幂 + 欧拉降幂

    R - M斐波那契数列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit  ...

  8. bzoj3884: 上帝与集合的正确用法 欧拉降幂公式

    欧拉降幂公式:http://blog.csdn.net/acdreamers/article/details/8236942 糖教题解处:http://blog.csdn.net/skywalkert ...

  9. Codeforces Round #536 (Div. 2) F 矩阵快速幂 + bsgs(新坑) + exgcd(新坑) + 欧拉降幂

    https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k} ...

随机推荐

  1. Codeforces 598D:Igor In the Museum

    D. Igor In the Museum time limit per test 1 second memory limit per test 256 megabytes input standar ...

  2. day10-Python运维开发基础(函数嵌套、nonlocal声明局部变量、闭包、locals/globals、lambda表达式)

    1. 函数的嵌套与nonlocal 声明局部变量 # ### 函数的嵌套 """ 函数和函数之间可以互相嵌套: 嵌套在内层的叫做内函数 乔涛在外层的叫做外函数 " ...

  3. 072、Java面向对象之定义构造方法

    01.代码如下: package TIANPAN; class Book { // 定义一个新的类 public Book() { // 构造方法 System.out.println("* ...

  4. yarn container 的日志路径

    /etc/hadoop/conf/yarn-site.xml 配置文件中 - yarn.nodemanager.log-dirs 指定本机的日志路径 (/hadoopfs/fs1/yarn/nodem ...

  5. C# FTp 上传,下载

    public class FtpHelper { string ftpServerIP; string ftpRemotePath; string ftpUserID; string ftpPassw ...

  6. leetcode844 Backspace String Compare

    """ Given two strings S and T, return if they are equal when both are typed into empt ...

  7. JdbcTemplate常用方法

    JdbcTemplate简介 JdbcTemplate是Spring JDBC的核心类,借助该类提供的方法可以很方便的实现数据的增删改查. Spring对数据库的操作在jdbc上面做了深层次的封装,使 ...

  8. JavaScript 字符编码

    JavaScript 字符编码 JavaScript 遵循 Unicode 字符编码规则.Unicode 字符集中每个字符使用 2 个字节来表示,这意味着用户可以使用中文来命名 Java)Script ...

  9. visio 2019 激活方法

    今日因工作需要使用visio,无奈下载2019版本需要激活,很多功能无法使用,最近在网上发现一个非常简单就是一个本地可执行脚本,本人已亲测完全激活成功,随分享给大家 复制下面代码: @echo off ...

  10. maven知识结构笔记

    1.什么是maven Maven 翻译为"专家"."内行",是 Apache 下的一个纯 Java 开发的开源项目.基于项目对象模型(缩写:POM)概念,Mav ...