NYOJ-1235-A/B Problem
来源:互联网 发布:python turtle 坐标 编辑:程序博客网 时间:2024/06/16 22:20
ACM模版
描述
题解
只要逆元学得足够好,这个题就是秒出思路,最后结果就是
裸逆元题,直接套模版就 OK 了,扩展欧几里得 GG。
代码
#include <iostream>using namespace std;const int MOD = 9973;/* * 扩展欧几里得法(求ax + by = gcd) */// 返回d = gcd(a, b);和对应于等式ax + by = d中的x、ylong long extendGcd(long long a, long long b, long long &x, long long &y){ if (a == 0 && b == 0) { return -1; // 无最大公约数 } if (b == 0) { x = 1; y = 0; return a; } long long d = extendGcd(b, a % b, y, x); y -= a / b * x; return d;}// 求逆元 ax = 1(mod n)long long modReverse(long long a, long long n){ long long x, y; long long d = extendGcd(a, n, x, y); if (d == 1) { return (x % n + n) % n; } else { return -1; // 无逆元 }}int main(int argc, const char * argv[]){ int T; cin >> T; long long n, B; while (T--) { cin >> n >> B; long long b = modReverse(B, MOD); cout << (n * b) % MOD << '\n'; } return 0;}
1 0
- NYOJ-1235-A/B Problem
- NYOJ - A*B Problem
- NYOJ - A-B Problem
- NYoj A*B Problem
- NYOJ-A^B Problem
- NYOJ-A/B Problem
- NYOJ A-B Problem
- NYOJ A-B Problem
- NYOJ---A+B Problem II
- NYOJ 524 A-B Problem
- NYOJ - A+B Problem II
- NYOJ 485 A*B Problem
- NYOJ.524.A-B Problem
- nyoj-485-A*B Problem
- NYOJ 1 A+B Problem
- nyoj-473-A^B Problem
- nyoj 485 A*B Problem
- nyoj 524 A-B Problem
- angular-单页面跳转ui-view
- 二叉树初始化
- 104. Maximum Depth of Binary Tree
- poj 1017 Packets
- springmvc常用注解标签详解
- NYOJ-1235-A/B Problem
- C/C++:宏定义中的#与##
- Redis学习系列——Redis安装
- Problem A: 时间类的构造和输出
- angular-单页面多行数据展示-自定义命名-ui-view
- Problem B: 时间类的成员读写
- linux_2-LDAP网络用户账户
- Spring Boot搭建spring+springMVC+Mybatis简单Demo
- 如何优雅的“编写”api接口文档