hdu2837数论
http://acm.hdu.edu.cn/showproblem.php?pid=2837
- // a^b%p=a^(b%phi(p)+phi(p))%p
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<cmath>
- #include<algorithm>
- #include<bitset>
- #include<iomanip>
- using namespace std;
- #define INT long long
- INT euler( int n)
- {
- INT ret=1,i;
- for (i=2;i*i<=n;i++)
- if (n%i==0){
- n/=i,ret*=i-1;
- while (n%i==0)
- n/=i,ret*=i;
- }
- if (n>1)
- ret*=n-1;
- return ret;
- }
- INT Pow( INT a , INT b , INT m )
- {
- INT ans = 1 ;
- while( b )
- {
- if( b & 1 )
- {
- ans = ans * a % m ;
- }
- a *= a ;
- a %= m ;
- b >>= 1 ;
- }
- return ans % m ;
- }
- INT fun2( int a , int b , int m )
- {
- INT ans = 1 ;
- for( int i = 1 ; i <= b ; ++i )
- {
- ans *= a ;
- if( ans >= m )
- return ans ;
- }
- return ans ;
- }
- INT fun1( int n , int m )
- {
- INT phi = euler( m ) ;
- if( n < 10 )
- return n ;
- INT a = fun1( n / 10 , phi ) ;
- INT b = fun2( n % 10 , a , m ) ;
- if( b >= m )
- {
- INT ans = Pow( n % 10 , a + phi , m ) ;
- if( ans == 0 )
- ans += m ;
- return ans ;
- }
- return b ;
- }
- int main()
- {
- int Case , n , m , p ;
- cin >> Case ;
- while( Case-- )
- {
- cin >> n >> m ;
- INT ans = fun1( n , m ) % m ;
- cout << ans << endl ;
- }
- return 0 ;
- }
hdu2837数论的更多相关文章
- Codeforces Round #382 Div. 2【数论】
C. Tennis Championship(递推,斐波那契) 题意:n个人比赛,淘汰制,要求进行比赛双方的胜场数之差小于等于1.问冠军最多能打多少场比赛.题解:因为n太大,感觉是个构造.写写小数据, ...
- NOIP2014 uoj20解方程 数论(同余)
又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, ...
- 数论学习笔记之解线性方程 a*x + b*y = gcd(a,b)
~>>_<<~ 咳咳!!!今天写此笔记,以防他日老年痴呆后不会解方程了!!! Begin ! ~1~, 首先呢,就看到了一个 gcd(a,b),这是什么鬼玩意呢?什么鬼玩意并不 ...
- hdu 1299 Diophantus of Alexandria (数论)
Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)
4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 290 Solved: 148[Submit][Status ...
- bzoj2219: 数论之神
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- hdu5072 Coprime (2014鞍山区域赛C题)(数论)
http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...
- ACM: POJ 1061 青蛙的约会 -数论专题-扩展欧几里德
POJ 1061 青蛙的约会 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu Descr ...
- 数论初步(费马小定理) - Happy 2004
Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2 ...
随机推荐
- Codeforces Round #243 (Div. 1)-A,B,C-D
此CF真是可笑.. . 由于早晨7初始点,因此,要做好CF时间已经17没有休息一小时,加上中午5小时耐力赛. 心里很清楚.是第一个问题的时候,几乎被解读为寻求最大的领域和.然后找到一个水体,快速A降. ...
- jenkins综合cobertura,来电显示cobertura的report
我的项目是使用maven作为构建工具.左右maven如何整合jenkins请参阅: http://blog.csdn.net/yaominhua/article/details/40684355 本文 ...
- 图片alpha blending的计算
转载时请注明出处和作者联系方式:http://blog.csdn.net/mimepp作者联系方式:YU TAO <yut616 at sohu dot com> 一幅彩色图像的每一个像素 ...
- vim打开出现的文档^M什么
网上公开的一些代码,发现里面多^M符号.这是什么? 我搜索^M没有效果,这应该是一个特殊的控制字符.找换行的结果是不.在每一行的末尾是回车,代替它周围包裹,对于由线定义不同的编码系统是不一样的. li ...
- ReSharper C++计划上市
ReSharper是著名的VS代码生成工具,去年夏天,JetBrains公司就发布了ReSharper将推出支持C++的版本. ReSharper C++ EAP(Early Access Progr ...
- Guava之简介
1.介绍 Guava最初是在2007年作为“Google Collection Library” 出现的,这个项目在处理Java集合时提供了一些有用的工具,Google的这个guava项目已经成为了 ...
- leetcode第八题--String to Integer (atoi)
Problem: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible inp ...
- javascript 10进制和64进制的转换
原文:javascript 10进制和64进制的转换 function string10to64(number) { var chars = '0123456789abcdefghigklmnopqr ...
- /bin/bash^M: bad interpreter: No such file or directory
<今天遇到的问题, 网上有非常多类似的文章, 个人记录下来, 加深记忆, 已经明确的就绕路吧.> 运行一个脚本full_build.sh 时, 一直是提示我: -bash: ./f ...
- css3动画实例测试
1.css3动画属性分析(2016-5-11) 1.transition: 规定属性变换规则,可以这样讲.transition(a,b,c,d); a:要变换的属性: b:过渡时间: c:运动方式: ...