hdu-5690 All X(快速幂+乘法逆元)
题目链接:
All X
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
F(x,m) mod k ≡ c
每组测试数据占一行,包含四个数字x,m,k,c
1≤x≤9
1≤m≤10^10
0≤c<k≤10,000
第一行输出:"Case #i:"。i代表第i组测试数据。
第二行输出“Yes” 或者 “No”,代表四个数字,是否能够满足题目中给的公式。
//#include <bits/stdc++.h> #include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
//const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e5+;
LL x,m,k,c;
LL mod;
LL fastmod(LL x,LL y)
{
LL ans=,base=x;
while(y)
{
if(y&)ans*=base,ans%=mod;
base*=base;
base%=mod;
y=(y>>);
}
return ans;
}
int main()
{
int t,cnt=;
scanf("%d",&t);
while(t--)
{
printf("Case #%d:\n",cnt++);
scanf("%I64d%I64d%I64d%I64d",&x,&m,&k,&c);
mod=*k;
LL fx=fastmod(,m);
LL ans=(fx*x%mod-x%mod)%mod;
if(ans==*c)printf("Yes\n");
else printf("No\n");
} return ;
}
hdu-5690 All X(快速幂+乘法逆元)的更多相关文章
- hdu-4990 Reading comprehension(快速幂+乘法逆元)
题目链接: Reading comprehension Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- 51Nod 1013 3的幂的和 快速幂 | 乘法逆元 | 递归求和公式
1.乘法逆元 直接使用等比数列求和公式,注意使用乘法逆元 ---严谨,失细节毁所有 #include "bits/stdc++.h" using namespace std; #d ...
- 2016"百度之星" - 初赛(Astar Round2A)--HDU 5690 |数学转化+快速幂
Sample Input 3 1 3 5 2 1 3 5 1 3 5 99 69 Sample Output Case #1: No Case #2: Yes Case #3: Yes Hint ...
- HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)
A Boring Question Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- Happy 2004(快速幂+乘法逆元)
Happy 2004 问题描述 : Consider a positive integer X,and let S be the sum of all positive integer divisor ...
- HDU 1061 Rightmost Digit --- 快速幂取模
HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...
- HDU4869:Turn the pokers(快速幂求逆元+组合数)
题意: 给出n次翻转和m张牌,牌相同且一开始背面向上,输入n个数xi,表示xi张牌翻转,问最后得到的牌的情况的总数. 思路: 首先我们可以假设一开始牌背面状态为0,正面则为1,最后即是求ΣC(m,k) ...
- HDU.2640 Queuing (矩阵快速幂)
HDU.2640 Queuing (矩阵快速幂) 题意分析 不妨令f为1,m为0,那么题目的意思为,求长度为n的01序列,求其中不含111或者101这样串的个数对M取模的值. 用F(n)表示串长为n的 ...
- HDU 5667 构造矩阵快速幂
HDU 5667 构造矩阵快速幂 题目描述 解析 我们根据递推公式 设 则可得到Q的指数关系式 求Q构造矩阵 同时有公式 其中φ为欧拉函数,且当p为质数时有 代码 #include <cstdi ...
随机推荐
- Firefox 设置技巧
在Firefox地址栏中输入“about:cache”并键入回车,接着将显示Firefox的内存缓冲设置与磁盘高速缓存设置.如果在页面上单击“List Cache Entries”链接,我们还可以查看 ...
- 索引的实现:B+树
[ http://blog.csdn.net/stormbjm/article/details/12033673 ] 见<数据库系统概念>P323. [从B树.B+树.B*树谈到R ...
- Chrome developer tool:本人钟爱的 console、Network 功能简谈
在最开始时,本人调试查看网页,一直用的是 firefox 的 firebug 插件,并没有使用 chrome 的 developer tool .只不过,在日常生活使用过程中,一直使用的是 chrom ...
- JavaScript的因为所以
各位看官,楼主开始说过写几篇博客,这是这个系列的最后一集.吾以为:了解JavaScript的身世之谜,掌握其近乎心想事成的变量系统,了解其解析运行的偷梁换柱之法,熟悉布大师迂回曲折的OOP实现.那你离 ...
- gitignore无效最简单解决办法
git rm --cached 文件或者文件夹 git commit 提交 git push 提交
- windows apache vhost 403 error
<Directory D:\workspace\ecshop> Options FollowSymLinks AllowOverride None Order deny,allow all ...
- Cross-Browser HTML5 Placeholder Text
One of the nice enhancement in HTML5 web form is being able to add placeholder text to input fields. ...
- Java常见排序算法之折半插入排序
在学习算法的过程中,我们难免会接触很多和排序相关的算法.总而言之,对于任何编程人员来说,基本的排序算法是必须要掌握的. 从今天开始,我们将要进行基本的排序算法的讲解.Are you ready?Let ...
- Codeforces Round #244 (Div. 2) B. Prison Transfer 线段树rmq
B. Prison Transfer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...
- cdoj 1150 排名表 拓扑排序
排名表 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1150 Descrip ...