AlbertMourato

Untitled

Feb 24th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <bits/stdc++.h>
  3. //%lld
  4. typedef long long ll;
  5. using namespace std;
  6.  
  7. bool comp(int a, int b){
  8.     return a>b;
  9. }
  10.  
  11. ll primo[1000000];
  12. ll vetor[1000000];
  13. ll aux[1000];
  14. int main(){  
  15.     for(ll i = 1;i<=1000000;i++){
  16.             primo[i]=1;
  17.         }
  18.         for(ll i = 2;i<=1000000;i++){
  19.             if(primo[i]){
  20.                     for(ll j = 2*i;j<=1000000;j+=i){
  21.                         primo[j] = 0;
  22.                     }
  23.             }
  24.     }
  25.     int a, b, c, d, z = 0, maior = 0;
  26.     bool p = false;
  27.     cin>>a>>b;
  28.     for(int i = a;i<=b;i++){
  29.         if(primo[i]==1){
  30.             aux[z] = i;
  31.             z++;
  32.         }
  33.     }
  34.    
  35.     for(int i = 1;i<=z;i++){
  36.         int t = aux[i]-aux[i-1];
  37.         vetor[aux[i]-aux[i-1]]++;
  38.     }
  39.    
  40.     int saida = 0, q = 0;
  41.     for(int i = 0;i<=b;i++){
  42.         if(vetor[i]>saida){
  43.             saida = vetor[i];
  44.             q = i;
  45.         }
  46.     }
  47.  
  48.     if(q==0)cout<<"-1"<<endl;
  49.     else cout<<q<<endl;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment