# 1020. Big Integer（高精度运算）

1. Big Integer
Total: 11039 Accepted: 3632 Rating:

Time Limit: 1sec Memory Limit:32MB
Description
Long long ago, there was a super computer that could deal with VeryLongIntegers(no VeryLongInteger will be negative). Do you know how this computer stores the VeryLongIntegers? This computer has a set of n positive integers: b1,b2,…,bn, which is called a basis for the computer.

The basis satisfies two properties:
1) 1 < bi <= 1000 (1 <= i <= n),
2) gcd(bi,bj) = 1 (1 <= i,j <= n, i ≠ j).

Let M = b1*b2*…*bn

Given an integer x, which is nonegative and less than M, the ordered n-tuples (x mod b1, x mod b2, …, x mod bn), which is called the representation of x, will be put into the computer.

Input
The input consists of T test cases. The number of test cases (T) is given in the first line of the input.
Each test case contains three lines.
The first line contains an integer n(<=100).
The second line contains n integers: b1,b2,…,bn, which is the basis of the computer.
The third line contains a single VeryLongInteger x.

Each VeryLongInteger will be 400 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).

Output
For each test case, print exactly one line – the representation of x.
The output format is:(r1,r2,…,rn)
Sample Input
2

3
2 3 5
10

4
2 3 5 7
13
Sample Output
(0,1,0)
(1,1,3,6)

c语言

#include <stdio.h>
#include <string.h>
int mod(char dividend[], int divisor) {
int p = 0;
int temp = dividend[p++] - '0';
while (1) {
while (temp < divisor) {
if (p == (strlen(dividend)) {
return temp;
} else {
temp = temp * 10 + dividend[p++] - '0';
}
}
temp %= divisor;
}
}

int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (int i = 0; i < n; i++) {
int m;
int base[100];
char bigint[400];
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &base[i]);
}
scanf("%s", bigint);
printf("(");
for (int i = 0; i < m; i++) {
printf("%d", mod(bigint, base[i]));
if (i != m - 1) {
printf(",");
}

}
printf(")\n");
}
}
return 0;
}

cpp语言 可以正常通过。

#include<iostream>
#include<string>
using namespace std;
int mod(string dividend,int divisor)
{
int p = 0;//对被除数的位数的指针
int temp = dividend[p++] - '0';
while(1)
{
while(temp < divisor)
{
if(p == dividend.size())    return temp;//如果指针超过被除数最低位还不能找到比除数小的数跳出，此时temp为答案
temp = temp * 10 + dividend[p++] - '0';
}
temp %= divisor;
}
}
int main()
{
int t,n,b[102];
string num;
cin >> t;
while(t--)
{
cin >> n;
for(int i = 0;i < n;++i) cin >> b[i];
cin >> num;
cout << "(";
for(int i = 0;i < n;++i)
{
cout << mod(num,b[i]);
if(i != n - 1)  cout <<",";
}
cout << ")" << endl;
}
return 0;
}

• 本文已收录于以下专栏：

## 1020. Big Integer

• Er_mu
• 2014年09月23日 17:58
• 401

## Sicily 1020. Big Integer

• q271736642
• 2013年09月08日 17:46
• 639

## [sicily]1020. Big Integer

1020. Big Integer Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Long l...
• luohuang0423
• 2015年09月23日 16:41
• 203

## sicily 1020. Big Integer

1020. Big Integer Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Long long a...
• huangjq36SYSU
• 2015年11月17日 16:00
• 199

## [sicily] 1020. Big Integer

1020. Big IntegerConstraintsTime Limit: 1 secs, Memory Limit: 32 MBDescriptionLong long ago, there w...
• juanqinyang
• 2016年05月12日 20:08
• 159

## 1020. Big Integer大数求模

/* 1020. Big Integer大数求模 题目大意： 给出n个整数b1,b2,...,bn，和一个大整数x，求x对每个数bi取模的结果。 n...
• lhsheng1989
• 2013年01月08日 21:47
• 417

## Sicily 1020 Big Integer(高精度运算)

//高精度取模运算 //一开始套了个原先自己写的模板，高精度%高精度，结果TLE 2次，原因很明显，被除数可达400位，2E除以2就要做1E次减法必定TLE //所以只能自己写个最原始最朴素的才能...
• ChinaCzy
• 2010年07月12日 02:47
• 2079

## 算法1：1020. Big Integer

• oTongHua12345
• 2016年03月04日 17:17
• 336

## [sicily online]1020. Big Integer

Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description Long long ago, there wa...
• qiuchenl
• 2012年11月26日 16:05
• 728