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.
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.
Each VeryLongInteger will be 400 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).
2 3 2 3 5 10 4 2 3 5 7 13
Problem Source: ZSUACM Team Member
#include <string>
#include <vector>
using namespace std;
int main()
{
int group; //定义共有几组测试数据
cin>>group;
for(int i=0;i<group;i++) //用for循环计算各组测试数据
{
int num; //num是该组测试数据basis of computer的个数
vector<int> vb; //定义向量vb来存储basis of computer
int temp; //读取basis用
cin>>num;
for(int y=0;y<num;y++)
{
cin>>temp;
vb.push_back(temp); //将读取的basis加入向量vb中
}
string s; //存放VeryLongInteger,就是大数,这样不能用int或者long,会溢出
cin>>s;
for(int x=0;x<s.length();x++)
{
s[x]=s[x]-'0'; //将字符变成十进制数字
}
vector<int>::iterator it; //迭代
int totalm=0; //记录结果
cout<<"(";
int tmp;
for(it=vb.begin();it!=vb.end();it++) //逐一读取每个basis
{
tmp=*it;
for(int z=0;z<s.length();z++) //大数取模算法
{
totalm=(totalm*10+s[z])%tmp;
}
cout<<totalm;
if(it!=(vb.end()-1)) //安要求格式输出
cout<<",";
totalm=0; //归零,进行下一个循环
}
cout<<")";
cout<<endl;
}
return 0;
}