sicily_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 = b1b2...*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)

題目大意

給定一個高精度數(shù),求出它除以n個整形數(shù)的模,并寫成向量的形式。

思路

在處理數(shù)的過程中只留下模,防止數(shù)據(jù)溢出。

代碼

#include<iostream>
#include<string>
using std::cin;
using std::cout;
using std::string;

int mod(string divided, int divisor) {
  int p = 0, tmp = 0;
  tmp = divided[p++] - '0';
  while (true) {
    while (tmp < divisor) {
      if (p == divided.length()) return tmp;
      tmp = 10 * tmp + divided[p++] - '0';
    }
    tmp %= divisor;
  }
}

int main() {
  int T;

  cin >> T;
  while (T--) {
    int n, b[100 + 1];
    string x;

    cin >> n;
    for (int i = 0; i < n; i++) cin >> b[i];
    cin >> x;

    cout << '(';
    for (int Head = 1, i = 0; i < n; Head = 0, i++) {
      if (!Head) cout << ',';
      cout << mod(x, b[i]);
    }
    cout << ')' << endl;
  }
  return 0;
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容