Reduced ID Numbers
Description T. Chur teaches various groups of students at university U. Every u-student has a unique student identification number (SIN). A SIN S is an integer in the range 0≤s≤maxsin with Maxsin = 10 6-1. T. Chur finds this range of SINs too large for identification within her groups. For each group, she wants to find the smallest positive integer m, such this within the group all SINs reduced modulo m ar E unique.
Input on the first line of the input was a single positive integer N, telling the number of the test cases (groups) to follow. Each case starts with one line containing the integer G (1≤g≤300): The number of students in the group. The following G lines each contain one SIN. The SINs within a group is distinct, though not necessarily sorted.
Output for each test case, output one line containing the smallest modulus m, such it all SINs reduced modulo m is dist Inct.
Sample Input
2
1
124866
3
124866
111111
987651
Sample Output
1
8
Ideas for solving problems: marking arrays
There is no good way, starting from 1 enumeration, open a tag array bool P[i] means that there is no remainder is the ID of I Numbers, the occurrence of the word jump out of the loop, otherwise continue to mark until I first to make any one ID number to I are different, at this time I min, That is, for the smallest we want to meet each group each student number is different.
Note: Do not memset for each i (p,false,sizeof (p)), the array P[maxn] is a general time-out, simply initialize the possible p[1-i] to false.
Reference Code + partial explanation:
#include
#include
#include
#include #include #include
using namespace std;
const int MAXN=1000000+10;
int a[350];
BOOL P[MAXN]; Open a tag array
int main ()
{
///Freopen ("Input.txt", "R", stdin);
int t;cin>>t;
while (t--) {
int n;cin>>n;
for (int i=0;i>a[i];
int i=1;
while (1) {
bool ok=true;
memset (P,false,sizeof (P)); Tag array initialization for
(int j=0;j
Fibonacci Again
Problem Description There is another kind of Fibonacci numbers:f (0) = 7, f (1) = one, f (n) = f (n-1) + f (n-2) (n>=2).
Input input consists of a sequence of lines, each containing an integer n. (n < 1,000,000).
Output Print the word "yes" if 3 divide evenly into F (n).
Print the word "no" if not.
Sample Input
0 1 2 3 4 5
Sample Output
No no yes no no no
The thinking of solving problems: The application of congruence theorem.
Reference Code:
#include
#include
#include
#include #include #include
using namespace std;
const int MAXN=1000000+10;
int F[MAXN];
int main ()
{
// freopen ("Input.txt", "R", stdin);
f[0]=7; f[1]=11;
for (int i=2;i>n) {
if (f[n]==0) cout<< "Yes" <