Luo Gu P1154 cow stables points

 Luo Gu P1154 cow stables points

If (a congruence b) mod c; then c | (ab).

Find out the difference between the two n ^ 2 put every number, marking vis [cur].

From then begins the enumeration k n, if the flag does not exist for the current multiple of k and k in the log domain mk s, then the current value of the constant satisfied.

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn=5000+5;
 5 
 6 
 7 int vis[1000000+5];
 8 int a[maxn];
 9 int main()
10 {
11     int n;scanf("%d",&n);
12     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
13     for(int i=1;i<=n;i++)
14     {
15         for(int j=1;j<=n;j++)
16         {
17             if(i==j) continue;
18             vis[abs(a[i]-a[j])]=1;
19         }
20     }
21     for(int i=n;i<=1000000;i++)
22     {
23         if(!vis[i])
24         {
25             int flag=1;
26             for(int j=i;j<=1000000;j+=i)
27             {
28                 if(vis[j]) 
29                 {
30                     flag=0;break;
31                 }
32             }
33             if(flag)
34             {
35                 printf("%d\n",i);
36                 break;
37             }
38         }
39     }
40     return 0;
41 }

 

Guess you like

Origin www.cnblogs.com/Msmw/p/11319995.html