UVA1226 LA3997 Numerical surprises大数

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA1226 LA3997 Numerical surprises大数相关的知识,希望对你有一定的参考价值。

We suspect that for every positive integer N there exists an integer of the form 11 . . . 10 . . . 0 (a sequence of 1’s followed by 0 or more 0’s) that is divisible by N. For example, with N = 3, 111 is divisible by 3, with N = 4, 100 is divisible by 4, with N = 7, 11111 is divisible by 7. We want to verify this for some integers. The solution to this problem is to find two different numbers P and Q in the form of 11 . . . 1 (a sequence of 1’s) that have the same remainder when dividing by N. The difference D between P and Q will be in the form of 11 . . . 10 . . . 0 and divisible by N.
    In order to solve this problem, we have to start with finding the remainder when dividing a number in the form of 11 . . . 1 by N. Your task is to write a program to do this.
Input
The input file consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer and is not bigger than 20. The following lines describe the data sets.
    Each data set is described by two lines. The first line contains the integer N (1 < N < 109). The second line contains the integer number P (P contains at least one digit and at most 2000 digits).
Output
For each test case, write in one line the remainder when dividing P by N.
Sample Input
2
4
11
5
111
Sample Output
3
1

问题链接UVA1226 LA3997 Numerical surprises
问题简述:(略)
问题分析:大数计算问题,用Java或Python来解决。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的Java语言程序如下:

/* UVA1226 LA3997 Numerical surprises */

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for (int i = 0; i < n; i++) {
            long a = input.nextLong();
            BigInteger x = input.nextBigInteger();
            System.out.println(x.mod(BigInteger.valueOf(a)));
        }
    }
}

AC的Python语言程序如下:

# UVA1226 LA3997 Numerical surprises

n = int(input())
for i in range(n):
	x = int(input())
	y = int(input())
	print(y % x)

以上是关于UVA1226 LA3997 Numerical surprises大数的主要内容,如果未能解决你的问题,请参考以下文章

UVA280 LA5588 VertexDFS

UVA557 LA5578 Burger概率

UVA763 LA5339 Fibinary Numbers大数

UVA1224 LA3904 Tile Code铺砖问题

UVA1482 LA5059 Playing With StonesSG函数

UVA1258 LA4721 Nowhere Money数学计算