数学专项number_theory:UVa 10692
来源:互联网 发布:行业分析怎么做 知乎 编辑:程序博客网 时间:2024/06/01 09:21
只能说数论方面的基本知识还是太匮乏了,而且lrj书上处理的情况都比较特殊。导致一遇到a和m不互质的情况我就一筹莫展了……无意间找到了一个公式才让我解决了这道题:a^x≡a^(x%phi(c)+phi(c))(mod c)。这个公式对a、c不互质的情况也成立,应该算是欧拉公式的扩展吧,可是因为没有系统学习过,所以也不知道怎么证明。求数学帝指点,或者推荐点资料神马的。
#include <iostream>#include <cstdio>#include <string>#include <sstream>using namespace std;int phi[10010];void init(){ for(int i=2;i<=10000;i++) phi[i]=0; phi[1]=1; for(int i=2;i<=10000;i++) if(!phi[i]) for(int j=i;j<=10000;j+=i) { if(!phi[j]) phi[j]=j; phi[j]=phi[j]/i*(i-1); }}string s;int m,n;int a[20];int pow_mod(int A,int N,int M){ if(N==0) return 1; int ans=pow_mod(A,N/2,M); ans=(long long)ans*ans%M; if(N%2==1) ans=(long long)ans*A%M; return ans;}int dfs(int dep,int mod){ if(dep==n-1) return a[dep]%mod; int tmp=dfs(dep+1,phi[mod]); int ans=pow_mod(a[dep],tmp+phi[mod],mod); return ans;}int main(){ freopen("in.txt","r",stdin); init(); int kase=1; while(getline(cin,s)&&s[0]!='#') { istringstream in(s); in>>m>>n; for(int i=0;i<n;i++) in>>a[i]; cout<<"Case #"<<kase++<<": "; cout<<dfs(0,m)<<endl; } return 0;}
- 数学专项number_theory:UVa 10692
- 数学专项number_theory:UVa 10515
- 数学专项number_theory:UVa 10622
- 数学专项number_theory:UVa 10127
- 数学专项number_theory:UVa 10090
- 数学专项number_theory:UVa 10539
- 数学专项number_theory:UVa 11105
- 数学专项number_theory:UVa 11490
- 数学专项number_theory:UVa 11728
- 数学专项number_theory:UVa 10951
- 数学专项number_theory:UVa 756
- 数学专项number_theory:UVa 718
- 数学专项number_theory:UVa 294
- 数学专项number_theory:UVa 10368
- 数学专项number_theory:UVa 10162
- 数学专项number_theory:UVa 11768
- 数学专项number_theory:UVa 10236
- 数学专项number_theory:LA 4079
- GUI系统之SurfaceFlinger(3)Android中的本地窗口FramebufferNativewindow
- UCSC浏览器的安装
- 第10期中国智能家居主题沙龙将于5月25日在上海举办
- php最详细的配置文件(中文注释)
- 数据库设计规范化的五个要求
- 数学专项number_theory:UVa 10692
- cocos2d-x+lua+cocosbuilder+luaproxy开发中遇到的读取子node以及事件绑定问题
- Windows下如何安装MariaDB
- linux信号量
- ArcGIS Server for JavaScript api 3.3 离线部署
- Effective C++读书笔记 第六部分 继承与面向对象设计
- VirtualBox Mac OS X 全屏设置
- 成为Android高手所经历的阶段
- Sublime Text 2 快捷键