Topic Links:
http://poj.org/problem?id=2769
Main topic:
There are n students, each student has a unique student ID number (0~10^6), but for the student ID number range is a little big,
Therefore, I hope to find a minimum positive integer m, so that all students ' student ID number is different than the modulus m. So the question comes
: How much is this m?
Ideas:
Test m from 1, save all student ID numbers for m, and if found with the same result, increase
The value of large m continues to be tested until all students are satisfied that the student ID number is different for M.
AC Code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace Std;bool p[100010];int Num[100010];int Main () { int t,m,n; Cin >> T; while (t--) { cin >> N; for (int i = 0; i < N; ++i) cin >> Num[i]; int flag; int M = 1; while (1) { flag = 1; memset (P,0,sizeof (P)); for (int i = 0; i < N; ++i) { if (p[num[i]%m]) { flag = 0; break; } P[NUM[I]%M] = 1; } if (flag) break ; m++; } cout << M << endl; } return 0;}
POJ2769 reduced ID Numbers "congruence theorem"