题目链接:

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---欧拉降幂&指数循环节的更多相关文章

  1. 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. φ ...

  2. 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 ...

  3. FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时 ...

  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. fzou 1759 Super A^B mod C

    Problem 1759 Super A^B mod CAccept: 456    Submit: 1488Time Limit: 1000 mSec    Memory Limit : 32768 ...

  6. FZU 1759 题解 欧拉降幂

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

  7. FZU1759(SummerTrainingDay04-B 欧拉降幂公式)

    Problem 1759 Super A^B mod C Accept: 1056    Submit: 3444Time Limit: 1000 mSec    Memory Limit : 327 ...

  8. 【转】【关于 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 ...

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

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

随机推荐

  1. php将“\\”转换成“\”的例子

    str_replace('\\\\', '\\', $url);

  2. 使用rem单位的问题——Google下字体很大

    rem的看法 rem单位确实好处蛮多的,它是相对于根节点,让我们整个网站单位可以统一.还可以让我们的字体更好的自适应网站的大小.但是,你用过了就知道,它会出现一个问题: 用Chrome浏览器打开你做的 ...

  3. 常用Oracle的SQL语句20181206更新

    --clob转字符串:dbms_lob.substr() --锁表:select object_name,machine,s.sid,s.serial# from v$locked_object l, ...

  4. sql server存储过程中SELECT 与 SET 对变量赋值的区别 转自Theo

    SQL Server 中对已经定义的变量赋值的方式用两种,分别是 SET 和 SELECT. 对于这两种方式的区别,SQL Server 联机丛书中已经有详细的说明,但很多时候我们 并没有注意,其实这 ...

  5. quartz---定时器(配置注解方式&配置xml方式)

    本入门案例基于spring和quartz整合完成. 第一步:创建maven工程,导入spring和quartz相关依赖 第二步:创建任务类 第三步:在spring配置文件中配置任务类 第四步:在spr ...

  6. Linux常用指令整理

    Linux常用命令整理 快捷键 [Tab] [Tab] 接在一串指令的第一个字的后面,则为"命令补全": [Tab] 接在一串指令的第二个字以后时,则为"文件补齐&quo ...

  7. flask接收前台的ajax的post数据

    html <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8& ...

  8. JavaScript this指向相关内容

    1,默认绑定this指向windw对象 看代码: function test(C){ var a = 123 function b(){}; } 在预编译环节当中. OA{ arguments:[1] ...

  9. String Control

    using System; using System.Collections.Generic; using System.Text; using System.Web; using System.We ...

  10. vue2.0中v-on绑定自定义事件的理解

    vue中父组件通过prop传递数据给子组件,而想要将子组件的数据传递给父组件,则可以通过自定义事件的绑定. 每个Vue实例都实现了[事件接口],即: 1.使用 $on(eventName) 监听事件 ...