A/B----乘法逆元

A/B

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5491    Accepted Submission(s): 4275


Problem Description
要求(A/B)%9973,但由于A很大,我们只给出n(n=A%9973)(我们给定的A必能被B整除,且gcd(B,9973) = 1)。
 

Input
数据的第一行是一个T,表示有T组数据。
每组数据有两个数n(0 <= n < 9973)和B(1 <= B <= 10^9)。
 

Output
对应每组数据输出(A/B)%9973。
 

Sample Input
2 1000 53 87 123456789
 

Sample Output
7922 6060
 

Author
xhd
 
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1576


逆元的水题,a/b等于a*(b的逆元);

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#define LL long long
using namespace std;
const int p=9973;
LL inv(LL t, LL p) {
    return t==1?1:(p-p/t)*inv(p%t,p)%p;
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        LL n,b;
        scanf("%lld%lld",&n,&b);
        LL x=inv(b%p,p);
        printf("%lld\n",n*x%p);
    }
}



#include <stdio.h> #include <stdlib.h> // 椭圆曲线点结构(包含无穷远点标识) typedef struct { int x; int y; int is_infinite; // 1表示无穷远点O,0为正常点 } ECPoint; // 椭圆曲线参数结构 typedef struct { int p; // 素数域 int a, b; // 曲线方程y^2 = x^3 + a*x + b ECPoint G; // 生成元基点 int n; // 基点G的阶数(可选) } ECCurve; //----------------------------------- // 学生需实现的函数(下方空白处编码) //----------------------------------- // 模运算(确保结果非负) int mod(int a, int p) { // TODO: 实现取模运算,处理负数情况 } // 模逆元(扩展欧几里得算法) int mod_inverse(int a, int p) { // TODO: 返回a mod p的逆元,若无解返回-1 } // 判断点是否在曲线上 int is_point_on_curve(ECPoint P, ECCurve curve) { // TODO: 若P是无穷远点返回1,否则验证是否满足方程 } // 椭圆曲线点加法 ECPoint ec_point_add(ECPoint P, ECPoint Q, ECCurve curve) { // TODO: 处理P=O, Q=O, P=-Q等情况,返回P+Q } // 椭圆曲线标量乘法(double-and-add) ECPoint ec_scalar_mult(int k, ECPoint P, ECCurve curve) { // TODO: 返回k*P的结果 } //----------------------------------- // 主函数与测试案例(已实现部分) //----------------------------------- int main() { // 示例曲线参数(简化版) ECCurve test_curve = { .p = 17, .a = 2, .b = 3, .G = {5, 6, 0}, // 合法基点(5,6) .n = 19 }; printf("=== ECC基础运算测试 ===\n"); // 测试用例1:点加法-计算G + G ECPoint G_plus_G = ec_point_add(test_curve.G, test_curve.G, test_curve); printf("G + G = (%d, %d)\t\n", G_plus_G.x, G_plus_G.y); // 测试用例2:标量乘法-计算3*G ECPoint threeG = ec_scalar_mult(3, test_curve.G, test_curve); printf("3G = (%d, %d)\t\n", threeG.x, threeG.y); return 0; }
最新发布
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值