1020. Big Integer
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
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)
Problem Source
ZSUACM Team Member
简单的高精度求余数,按照手工步骤执行下去就行。
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
int a[101];
while(t--)
{
int n;
string num;
cin>>n;
for(int i=0; i<n; i++)
{
cin>>a[i];
}
cin >> num;
for(int i=0; i<n; i++)
{
int tmp = 0;
for(int j=0; j<num.size(); j++)
{
tmp = (tmp*10 + num[j]-'0') % a[i];
}
a[i] = tmp;
}
cout<<"(";
for(int i=0; i<n-1; i++)
cout<<a[i]<<",";
cout<<a[n-1]<<")"<<endl;
}
// system("pause");
return 0;
}
本文介绍了一种处理非常大的整数求余运算的方法,并提供了一个具体的C++代码实现示例。该算法能够有效地处理长度达400字符的大整数,并将其转换为指定基数集的表示形式。
1768

被折叠的 条评论
为什么被折叠?



