http://blog.163.com/hong_feiy/blog/static/207325071201282324736756/
回想小学怎么做除法可以帮助理解大数求模
#include <iostream> #include <string> using namespace std; int div(string x, int b) { int r, k; for ( k = 0; k < x.length(); k++ ) { r = 10 * r + x.at(k) - '0'; // 大数求摩,好神奇! r %= b; // 因为高位的数字如果大于b,则该数字num 肯定等于b * n*10 + mo。 而mo就等于r % b } return r; } int main() { int t; int n; unsigned b[100]; string x; // Each VeryLongInteger will be 400 or fewer characters in length, // and will only contain digits (no VeryLongInteger will be negative). int r[100]; int m; int i, j; cin >> t; for( i = 0; i < t; i++ ) { cin >> n; m = 1; for( j = 0; j < n; j++) { cin >> b[j]; m*= b[j]; } cin >> x; for( j = 0; j < n; j++) { r[j] = div(x, b[j]); } cout << "("; for( j = 0; j < n-1; j++) { cout << r[j] << ','; } cout << r[j] << ')' << endl; } return 0; }