题目链接: 传送门

A^B mod C

Time Limit: 1000MS     Memory Limit: 65536K

思路

快速加和快速幂同时运用,在快速加的时候由于取模耗费不少时间TLE了,最后又进行了改写。

#include<stdio.h>
typedef __int64 LL;

LL mod_mulit(LL x, LL y,LL mod)
{
    LL res = 0;
    while (y)
    {
        if (y & 1)
        {
            res += x;
            while (res >= mod)
            {
                res -= mod;
            }
            //res = (res + x) % mod;  //取模运算耗费时间
        }
        x += x;
        while (x >= mod)
        {
            x -= mod;
        }
        //x = (x + x) % mod;
        y >>= 1;
    }
    return res;
}

LL mod_pow(LL x,LL n,LL mod)
{
    LL res = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            res = mod_mulit(res, x, mod);
        }
        x = mod_mulit(x,x,mod);
        n >>= 1;
    }
    return res;
}

int main()
{
    LL A,B,C;
    while (~scanf("%I64d %I64d %I64d",&A,&B,&C))
    {
        /*LL res = 1;
        while (B > 0)
        {
            if (B & 1)
            {
                res = mod_mulit(res,A,C);
            }
            A = mod_mulit(A,A,C);
            B >>= 1;
        }*/
        LL sum = mod_pow(A,B,C);
        printf("%I64d\n",sum);
    }
    return 0;
}

FZU 1752 A^B mod C(快速加、快速幂)的更多相关文章

  1. [FOJ 1752] A^B mod C

    Problem 1752 A^B mod C Accept: 750    Submit: 3205Time Limit: 1000 mSec    Memory Limit : 32768 KB   ...

  2. 福州大学oj 1752 A^B mod C ===>数论的基本功。位运用。五星*****

    Problem 1752 A^B mod C Accept: 579    Submit: 2598Time Limit: 1000 mSec    Memory Limit : 32768 KB P ...

  3. Anaconda快速加载opencv

    刚刚发现了两种Anaconda快速加载opencv的方法,亲测有效: 第一种: 直接在Navigator Environment 中搜opencv 如果搜不到,登陆Anaconda Cloud官网 h ...

  4. HDU 5187 zhx's contest 快速幂,快速加

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5187 bc(中文): http://bestcoder.hdu.edu.cn/contes ...

  5. 在NVIDIA A100 GPU中使用DALI和新的硬件JPEG解码器快速加载数据

    在NVIDIA A100 GPU中使用DALI和新的硬件JPEG解码器快速加载数据 如今,最流行的拍照设备智能手机可以捕获高达4K UHD的图像(3840×2160图像),原始数据超过25 MB.即使 ...

  6. 使用Huggingface在矩池云快速加载预训练模型和数据集

    作为NLP领域的著名框架,Huggingface(HF)为社区提供了众多好用的预训练模型和数据集.本文介绍了如何在矩池云使用Huggingface快速加载预训练模型和数据集. 1.环境 HF支持Pyt ...

  7. hdu 5690 2016"百度之星" - 初赛(Astar Round2A) All X 快速二次幂 || 寻找周期

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5690 题意:m个数字全为x mod k ?= c;其中m <= 1010,0 < c,k ...

  8. 快速傅里叶变换 & 快速数论变换

    快速傅里叶变换 & 快速数论变换 [update 3.29.2017] 前言 2月10日初学,记得那时好像是正月十五放假那一天 当时写了手写版的笔记 过去近50天差不多忘光了,于是复习一下,具 ...

  9. FZU 1650 1752 a^b mod c

    http://acm.fzu.edu.cn/problem.php?pid=1752 http://acm.fzu.edu.cn/problem.php?pid=1650 给跪了. 我的快速幂会越界. ...

随机推荐

  1. 也议 js闭包和ie内存泄露原理

    可以, 但小心使用. 闭包也许是 JS 中最有用的特性了. 有一份比较好的介绍闭包原理的文档. 有一点需要牢记, 闭包保留了一个指向它封闭作用域的指针, 所以, 在给 DOM 元素附加闭包时, 很可能 ...

  2. RHEL7挂载ISO做本地yum

    测试环境,网络yum源没有本地yum源下载速度快!Yum比起RPM装包的好处就是可以自己处理依赖关系,也就是自己安装相关的依赖包,用起来也是很方便,但是删包的时候也会删除依赖包,这里要非常小心 01. ...

  3. Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.2.3:run (default-cli) on project Maven_WebTest: Execution default-cli of goal org.codehaus.cargo:cargo-maven2-plugin:1.2.3:run failed: C

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  4. 12-rm 命令总结

    rm remove files or directories 删除目录或文件 [语法]: rm [选项] [参数] [功能介绍] rm命令可以删除一个目录中的一个或多个文件或目录,也可以将某个目录及其 ...

  5. 【Android 开发】: Android 消息处理机制之一: Handler 与 Message

    最近几讲内容,我们学习了Android中关于多线程的一些知识,上一讲我们讲解了异步任务 AsyncTask 的操作,Android中还提供了其他的线程操作,如Handler Message Messa ...

  6. model 的验证

    Ext.onReady(function(){ Ext.define('User', { extend: 'Ext.data.Model', fields: [ { name: 'name', typ ...

  7. Openstack Basic Networking 翻译

    自己翻译,加强理解.并学习英文和写作. 英文地址:http://docs.openstack.org/networking-guide/intro_basic_networking.html 目录: ...

  8. Struts2.3.4.1+Spring3.2.3+Hibernate4.1.9整合

    java教程|Struts2.3.4.1+Spring3.2.3+Hibernate4.1.9整合教程并测试成功一.创建项目二.搭建struts-2.3.4.11.struts2必须的Jar包(放到W ...

  9. 【CodeVS 1582】【SDOI 2009】E和D

    http://codevs.cn/problem/1582/ 首先我打了一张50*50的表(4用#代替) 并没有发现什么规律! 然后观察题解可得,我观察的是TimeMachine学长的题解 什么得到s ...

  10. git初体验(三)git分支

    分支的理念就是分身,就像孙悟空拔出猴毛变出很多跟自己一模一样的猴子,然后每个猴子做自己的事情互不干涉,等到所有猴子做完之后,猴子集合来合并劳动成果,然后悟空就把那些猴子猴孙门统统收回了. 你创建了一个 ...