Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //3413 - Reduced ID Numbers
- //Live Archive
- /*
- Queremos achar o menor k para que todo a,b da entrada não aconteça que a%k = b%k
- a%k = b%k
- a%k - b%k = 0
- (a-b)%k = 0
- Seja x = abs(a-b)
- Para todo a,b teste todos os possíveis valores de k de 1 até sqrt(x)
- Se sqrt(x)%k = 0 então k e sqrt(x)/k não são valores válidos.
- Marque todos os valores não validos, depois procure o primeiro valor não marcado.
- */
- #include <cstdio>
- #include <cstdlib>
- #include <string>
- #include <cmath>
- #include <cstring>
- #include <algorithm>
- #include <utility>
- #include <queue>
- #include <stack>
- #include <vector>
- #include <map>
- #include <iostream>
- #define ln printf("\n")
- using namespace std;
- int n;
- int r[330];
- bool mark[1000010];
- bool read(){
- scanf("%d", &n);
- for(int i = 0; i < n; i++){
- scanf("%d", &r[i]);
- }
- return true;
- }
- void combine(int x){
- for(int i = 1; i*i <= x; i++){
- if(!(x%i)){
- mark[i] = true;
- mark[x/i] = true;
- }
- }
- }
- void process(){
- memset(mark, false, sizeof(mark));
- for(int i = 0; i < n; i++){
- for(int j = i+1; j < n; j++){
- combine(abs(r[i] - r[j]));
- }
- }
- int res = 1;
- while(mark[res]) res++;
- printf("%d\n", res);
- }
- int main(){
- //freopen("in", "r", stdin);
- int cases; scanf("%d", &cases);
- while(cases-- && /**/ read()){
- process();
- }
- //while(1);
- return 0;
- }
Add Comment
Please, Sign In to add comment