Description
Long long ago, there was a super computer that cocould 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 ).
Outputfor each test case, print exactly one line -- the representation of X.
The output format is :( R1, R2,..., RN) Sample inputcopy sample input to clipboard
232 3 51042 3 5 713
Sample output
(0,1,0)(1,1,3,6)
#include <iostream>#include <string>#include <string.h>using namespace std; int* findMod(string str, int* arr, int len) { int size = str.size(); int* arrt = new int[len]; memset(arrt, 0, sizeof(int) * len); for (int i = 0; i != size; ++i) { for (int j = 0; j != len; ++j) { arrt[j] = (arrt[j] * 10 + (str[i] - ‘0‘)) % arr[j]; } } return arrt;} int main(int argc, char* argv[]){ int T, n, *arr; string x; cin >> T; while (T--) { cin >> n; arr = new int[n]; for (int i = 0; i != n; ++i) cin >> arr[i]; cin >> x; int *result = findMod(x, arr, n); cout << "("; for (int i = 0; i != n - 1; i++) cout << result[i] << ","; cout << result[n - 1] << ")" << endl; } return 0;}
Because the space is still very large, so I used space for time in mod, in fact, this implementation is not good, because the applied space is not released at all. In this case, the time difference is only over 0.07.
Sicily 1020. Big integer