kburnik

C++ - Zadatak MaxProst

Jan 7th, 2013
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // program prosti :: eratostenovo sito :: u intervalu [A,B]
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6. typedef long long int lint;
  7.  
  8. int sumznam(int n) {
  9.     int s = 0;
  10.     if (n/10 == 0) return 1;
  11.     while (n>0) {
  12.         s += n%10;
  13.         n/=10;    
  14.     }        
  15.     return s;
  16. }
  17.  
  18. const int VEL = 1000001;
  19. int eratosten[VEL] = {0};
  20.    
  21. int main() {
  22.     lint a,b;
  23.     lint razine[10]={0};
  24.            
  25.     cin >> a >> b;
  26.  
  27.  
  28.     eratosten[1]=1;
  29.     lint e = (lint) sqrt(b);
  30.  
  31.     for (lint i = 2; i <= e; i++)
  32.         if ( !eratosten[i] )
  33.               for (lint j=i*2; j <= b; j+=i)
  34.                     eratosten[j]=1;
  35.    
  36.    
  37.     // lint x = 0;
  38.     int p,x;
  39.     int maxraz=0;
  40.     for (lint i = a; i <=b; i++) {
  41.         p = i;
  42.         x = 0;
  43.         while (!eratosten[p]) {
  44.             x++;
  45.             p = sumznam(p);
  46.         }
  47.         if (x>maxraz) maxraz=x;
  48.         razine[x]++;
  49.     }
  50.    
  51.     int s=0;
  52.     for (int i = 0; i <= maxraz; i++) {
  53.         cout << razine[i] << " ";    
  54.     }
  55.     cout << endl;
  56.  
  57.     return 0;
  58. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×