欧拉函数phic以及超大数的快速幂
题目:求a^b*c%mod;
其中b<=10^100000;
是不是很大.....
- /*当你要计算 A^B%C的时候
- 因为此题中的B很大,达到10^100000,所以我们应该联想到降幂公式。
- 降幂公式:A^B%C = A^(B%phi(C) + phi(C))%C
- 分两种情况:
- 当B<=phi(C)时,直接用快速幂计算A^B mod C
- 当B>phi(C)时,用快速幂计算A^(B mod phi(C)+phi(C)) mod C
- */
- #include <cstdio>
- #include <cstring>
- #include <cmath>
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <cstdlib>
- using namespace std;
- const int mod = 1e9+;
- typedef long long ll;
- ll phi(ll n) //求欧拉函数值
- {
- int ans=n,temp=n;
- for(int i=;i*i<=temp;i++)
- {
- if(temp%i==)
- {
- ans-=ans/i;
- while(temp%i== ) temp/=i;
- }
- }
- if(temp>) ans-=ans/temp;
- return ans;
- }
- ll mod_pow(ll x,ll n,ll mod) //快速幂
- {
- ll ans=;
- while(n)
- {
- if(n%==) ans=ans*x%mod;
- x=x*x%mod;
- n/=;
- }
- return ans;
- }
- ll a,c;
- char b[];
- int main()
- {
- while(scanf("%lld%s%lld",&a,b,&c)!=EOF)
- {
- c%=mod;
- a%=mod;
- ll phic=phi(mod);
- int i,len=strlen(b);
- ll res=,ans;
- for( i=;i<len;i++)
- {
- res=res*+b[i]-'';
- if(res>phic)
- break;
- }
- if(i==len)
- {
- ans=mod_pow(a,res,mod)*c%mod;
- }
- else
- {
- res=;
- for(int i=;i<len;i++)
- {
- res=res*+b[i]-'';
- res%=phic;
- }
- ans=mod_pow(a,res+phic,mod)*c%mod;
- }
- cout<<ans<<endl;
- }
- //cout<<mod_pow(2,3,mod);
- return ;
- }
欧拉函数phic以及超大数的快速幂的更多相关文章
- HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)
6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...
- UVA10200-Prime Time/HDU2161-Primes,例题讲解,牛逼的费马小定理和欧拉函数判素数。
10200 - Prime Time 此题极坑(本菜太弱),鉴定完毕,9遍过. 题意:很简单的求一个区间 ...
- BZOJ 2818 GCD 【欧拉函数 || 莫比乌斯反演】
传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 2818: Gcd Time Limit: 10 Sec Memory Limit ...
- 欧拉函数(小于或等于n的数中与n互质的数的数目)&& 欧拉函数线性筛法
[欧拉函数] 在数论,对正整数n,欧拉函数是少于或等于n的数中与n互质的数的数目.此函数以其首名研究者欧拉命名,它又称为Euler’s totient function.φ函数.欧拉商数等. 例如φ( ...
- BZOJ 3813--奇数国(线段树&欧拉函数&乘法逆元&状态压缩)
3813: 奇数国 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 755 Solved: 432[Submit][Status][Discuss] ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 4436 Solved: 1957[Submit][Status][Discuss ...
- poj2478 Farey Sequence (欧拉函数)
Farey Sequence 题意:给定一个数n,求在[1,n]这个范围内两两互质的数的个数.(转化为给定一个数n,比n小且与n互质的数的个数) 知识点: 欧拉函数: 普通求法: int Euler( ...
- 51Nod-1136 欧拉函数
51Nod: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1136 1136 欧拉函数 基准时间限制:1 秒 空间限制: ...
随机推荐
- ruby on rails 环境搭建(mac or ubuntu)
环境配置前操作 mac: app_store安装x-code ubuntu: 终端->配置文件->首选项->命令->以shell方式登录 安装RVM mac: $ ruby - ...
- 执行Go程序的三种方式及Go语言关键字
执行 Go 程序的三种方式及 Go 语言关键字 执行 Go 程序的三种方式 一.使用 go run 命令 二.使用 go build 命令 Step1. 对 go 源码源文件执行 go build 命 ...
- SAP OData $batch processing
例として.1回の呼び出しで100個の新しい商品を作成したい場合.最も簡単な方法は.$ batch要求を使用して100個のPOST呼び出しすべてを単一のサービス呼び出しにまとめることです. URIの末尾 ...
- 20155204第4次实验《Android程序设计》实验报告
20155204第四次实验报告 一.实验内容及步骤 1.Android Stuidio的安装测试: 安装 Android Stuidio 完成Hello World, 要求修改res目录中的内容,He ...
- 2017-2018-1 20155307 《信息安全系统设计基础》第san周学习总结
2017-2018-1 20155307 <信息安全系统设计基础>第三周学习总结 教材学习内容总结 无符号数和有符号数的特性,数字如何表示,IEEE标准,浮点数格式.(我感觉我把课下测试做 ...
- stardict词库
http://download.huzheng.org/zh_CN/ sudo tar -jxvf * -C /usr/share/stardict/dic
- WPF ControllTemplate Triggers小记 - 简书
原文:WPF ControllTemplate Triggers小记 - 简书 WPF中,样式模板中如果定义EventTrigger事件方式实现动画.那么需要注意两点: 1.对于绑定的属性的Event ...
- 【转载】图说C++对象模型:对象内存布局详解
原文: 图说C++对象模型:对象内存布局详解 正文 回到顶部 0.前言 文章较长,而且内容相对来说比较枯燥,希望对C++对象的内存布局.虚表指针.虚基类指针等有深入了解的朋友可以慢慢看.本文的结论都在 ...
- 3060 抓住那头奶牛 USACO
3060 抓住那头奶牛 USACO 时间限制: 1 s 空间限制: 16000 KB 题目等级 : 黄金 Gold 题目描述 Description 农夫约翰被告知一头逃跑奶牛的位置,想要立即抓住它, ...
- 搜索引擎ElasticSearch系列(四): ElasticSearch2.4.4 sql插件安装
一:ElasticSearch sql插件简介 With this plugin you can query elasticsearch using familiar SQL syntax. You ...