POJ2769 reduced ID Numbers "congruence theorem"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.