nyoj 1235 A/B Problem

A/B Problem

时间限制:1000 ms  |  内存限制:65535 KB

难度:3

描述

已知:

1. n = (A % 9973);

2. gcd(B, 9973) = 1;

计算:

(A / B) % 9973

输入

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

输出

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

样例输入

2

1000 53

87 123456789

样例输出

7922

6060

#include<string.h>
#include<stdio.h>
#define INF 0x3fffffff
long long x,y;
long long extend_gcd(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=extend_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n,b;
		int m=9973;
		long long  b1;
		scanf("%d %d",&n,&b);
		long long gcd=extend_gcd(b,m,x,y);
		if(gcd==1)
			b1=(x%m+m)%m;
		else
			b1=-1;
		printf("%lld\n",(n*b1)%m);
	}
	return 0;
}

  

时间: 2024-12-07 08:01:27

nyoj 1235 A/B Problem的相关文章

NYOJ 179 LK&#39;s problem (排序模拟)

链接:click here~~ 题意: 描述 LK has a question.Coule you help her? It is the beginning of the day at a bank, and a crowd  of clients is already waiting for the entrance door to  open. Once the bank opens, no more clients arrive, and  tellerCount tellers be

NYOJ 698 A Coin Problem (斐波那契)

链接:click here 题意: 描述 One day,Jiameier is tidying up the room,and find some coins. Then she throws the coin to play.Suddenly,she thinks of a problem ,that if throw n times coin ,how many situations of no-continuous up of the coin. Hey,Let's solve the

NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~

链接:click here 题意: A Simple Problem 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 You know, just as the title imply, this is a simple problem. In a contest, given the team-id, solved, penalty of all the teams, tell me the champion.If the numbers of solved pr

nyoj 513 A+B Problem IV 【Java大数】

这道题有点小坑.. 特殊数据 输入 0.0 0.0 输出 0 代码: import java.util.Scanner; import java.math.*; public class Main{ public static void main(String[] args){ Scanner cin = new Scanner(System.in); BigDecimal a, b, temp; temp = new BigDecimal("0.0"); while(cin.hasN

nyoj 803 A/B Problem 【Java大数】

 先用字符串将字符串接收,然后在用BigInteger就好了 代码: import java.util.Scanner; import java.math.*; public class Main{ public static void main(String[] args){ Scanner cin = new Scanner(System.in); while(cin.hasNextBigInteger()){ BigInteger aa, bb; //a = cin.nextBigDeci

NYOJ 477 A+B Problem III(认识fabs函数)

 A+B Problem III 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 求A+B是否与C相等. 输入 T组测试数据. 每组数据中有三个实数A,B,C(-10000.0<=A,B<=10000.0,-20000.0<=C<=20000.0) 数据保证小数点后不超过4位. 输出 如果相等则输出Yes 不相等则输出No 样例输入 3 -11.1 +11.1 0 11 -11.25 -0.25 1 2 +4 样例输出 Yes Yes No 刚开始

NYoj The partial sum problem(简单深搜+优化)

题目链接:http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=927 代码: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <math.h> 5 #include <algorithm> 6 #include <iostream> 7 using namespace std; 8

nyoj 623 A*B Problem II

A*B Problem II 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大量的乘法都会把他搞乱,所以他想请你写个程序帮他检验一下计算结果是否正确. 输入 有多组测试数据,每行给出一组m,n,k(0<m,n,k<=50).m,n,k表示两个矩阵的大小,其中: 矩阵A:m行n列. 矩阵B:n行k列. 接下来给出m*n个数表示矩阵A和n*k个数表示矩阵B,对于每个数s,0<

NYOJ 103 a+b Problem(2)

#include<stdio.h>#include<string.h>int main(){ char str1[1001],str2[1002]; int i,t,j=0; scanf("%d\n",&t); while(t--) { scanf("%s%s",str1,str2); int a[1001]={0},b[1001]={0},c[1001]={0}; int m,n,max=1; m=strlen(str1); n=s