直接来肯定WA,注意到a是可以被b整除的,那么就将所有的a和b分别分解因子,而对于所得的因子对应的位置,前者加后者减,然后将所有的因子相乘模除2011即可。
Run Time: 0sec
Run Memory: 312KB
Code Length: 1005Bytes
SubmitTime: 2012-02-10 12:01:52
// Problem#: 3392
// Submission#: 1208762
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int T, n, m;
int a, b, i;
int data[ 1001 ] = { 0 };
long long r;
cin >> T;
while ( T-- ) {
cin >> n >> m;
while ( n-- ) {
cin >> a;
for ( i = 2; i <= sqrtl( a ); i++ ) {
while ( a % i == 0 ) {
data[ i ]++;
a /= i;
}
}
data[ a ]++;
}
while ( m-- ) {
cin >> b;
for ( i = 2; i <= sqrtl( b ); i++ ) {
while ( b % i == 0 ) {
data[ i ]--;
b /= i;
}
}
data[ b ]--;
}
r = 1;
for ( i = 2; i <= 1000; i++ ) {
if ( data[ i ] != 0 ) {
r *= powl( i, data[ i ] );
r %= 2011;
data[ i ] = 0;
}
}
cout << r << endl;
}
return 0;
}