Exponial
Description
Everybody loves big numbers (if you do not, you might want to stop reading at this point). There are many ways of constructing really big numbers known to humankind, for instance:
- Exponentiation: 422016=42⋅42⋅...⋅422016 times422016=42⋅42⋅...⋅42⏟2016 times.
- Factorials: 2016!=2016 ⋅ 2015 ⋅ ... ⋅ 2 ⋅ 1.

In this problem we look at their lesser-known love-child the exponial, which is an operation defined for all positive integers n as
exponial(n)=n(n − 1)(n − 2)⋯21
For example, exponial(1)=1 and exponial(5)=54321 ≈ 6.206 ⋅ 10183230 which is already pretty big. Note that exponentiation is right-associative: abc = a(bc).
Since the exponials are really big, they can be a bit unwieldy to work with. Therefore we would like you to write a program which computesexponial(n) mod m (the remainder of exponial(n) when dividing by m).
Input
There will be several test cases. For the each case, the input consists of two integers n (1 ≤ n ≤ 109) and m (1 ≤ m ≤ 109).
Output
Output a single integer, the value of exponial(n) mod m.
Sample Input
2 42
5 123456789
94 265
Sample Output
2
16317634
39
题解:题意很好理解;直接说题。这是利用欧拉函数降幂公式求的,标准模版(记得开 long long);看代码()
AC代码为:(我下面有一篇讲下欧拉函数降幂公式)
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
LL N,M;
LL eular(LL m)
{
LL res=m,a=m;
for(LL i=2;i*i<=a;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 Fast_mod(LL x,LL n,LL m)
{
LL res=1;
while(n>0)
{
if(n & 1) res=(res*x)%m;
x=(x*x)%m;
n/=2;
}
return res;
}
LL work(LL n,LL m)
{
LL ans;
if(m==1) return 0;
else if(n==1) return 1;
else if(n==2) return 2%m;
else if(n==3) return 9%m;
else if(n==4) return Fast_mod(4,9,m);
else
{
LL phi=eular(m);
LL z=work(n-1,phi);
ans=Fast_mod(n,phi+z,m);
}
return ans;
}
int main()
{
cin>>N>>M;
cout<<work(N,M)<<endl;
return 0;
}
Exponial的更多相关文章
- Exponial (欧拉定理+指数循环定理+欧拉函数+快速幂)
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=2021 Description Everybody loves big numbers ...
- Exponial~(欧拉函数)~(发呆题)
Description Everybody loves big numbers (if you do not, you might want to stop reading at this point ...
- [数学][欧拉降幂定理]Exponial
Exponial 题目 http://exam.upc.edu.cn/problem.php?cid=1512&pid=4 欧拉降幂定理:当b>phi(p)时,有a^b%p = a^(b ...
- Urozero Autumn 2016. NCPC 2016
A. Artwork 倒过来并查集维护即可. #include<cstdio> #include<algorithm> using namespace std; const i ...
- NCPC 2016:简单题解
A .Artwork pro:给定N*M的白色格子,然后Q次黑棒,输出每次加黑棒后白色连通块的数量.(N,M<1e3, Q<1e4) sol:倒着离线做,并查集即可. (在线做法:http ...
- NCPC2016-E- Exponial
题目描述 Illustration of exponial(3) (not to scale), Picture by C.M. de Talleyrand-Périgord via Wikimedi ...
- Nordic Collegiate Programming Contest (NCPC) 2016
A Artwork B Bless You Autocorrect! C Card Hand Sorting D Daydreaming Stockbroker 贪心,低买高卖,不要爆int. #in ...
- ACM-数论-广义欧拉降幂
https://www.cnblogs.com/31415926535x/p/11447033.html 曾今一时的懒,造就今日的泪 记得半年前去武大参加的省赛,当时的A题就是一个广义欧拉降幂的板子题 ...
随机推荐
- Salesforce学习之路(十三)Aura案例实战分析
Aura相关知识整合: Salesforce学习之路(十)Aura组件工作原理 Salesforce学习之路(十一)Aura组件属性<aura:attribute /> Salesforc ...
- suseoj 1208: 排列问题 (STL, next_permutation(A.begin(), A.end()))
1208: 排列问题 时间限制: 1 Sec 内存限制: 128 MB提交: 2 解决: 2[提交][状态][讨论版][命题人:liyuansong] 题目描述 全排列的生成就是对于给定的字符集或 ...
- 创建sql自定义的函数及商品分页sql存储过程
--商品筛选时判断品牌ID是否存在 --select dbo.isValite(94,94)create function isValite(@brandId int,@bId int)returns ...
- django_0:项目流程
1.django-admin(.py) startproject mysite——创建项目project 得到__init__.py(说明工程以包结构存在) settings.py(当前工程的一些配置 ...
- Android ConstraintLayout
对官方例子加上自己的容器即可调整ConstraintLayout实时运行中观察这种布局的变化
- Docker从入门到掉坑(三):容器太多,操作好麻烦
前边的两篇文章里面,我们讲解了基于docker来部署基础的SpringBoot容器,如果阅读本文之前没有相关基础的话,可以回看之前的教程. Docker 从入门到掉坑 Docker从入门到掉坑(二): ...
- 纯css实现tab导航
仿照这个 实现了一个纯css的导航功能 html <div class="main"> <div id="contain1">列表一内容 ...
- 五年老Android,我决定转后端开发了!
今天给大家分享一些移动端(Android)开发学习后端开发(Java Web)的一些事儿,不知道从什么时候开始身边的同事都开始陆陆续续的在朋友圈发一些后端的文章如:Nginx.Docker.k8s类的 ...
- Android的系统框架
Android的系统架构采用了分层架构的思想,如图1所示.从上层到底层共包括四层,分别是应用程序程序层.应用框架层.系统库和Android运行时和Linux内核. 图1:Android系统架构图 每 ...
- 北冥'sfish
北冥咸鱼,其名为鲲.鲲之大,long long存不下.化而为鸟,其名为鹏.鹏之背,高精被卡废.怒而颓,其码若怪诞之吟.是咸鱼,颓废则将遇上cz.cz谁,大佬也.<大佬说>者,志奆者也.&l ...