josiftepe

Untitled

Dec 21st, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include <stdio.h> //standard input/output
  2. #include <stdlib.h> // standard library, malloc..
  3. int max(int a, int b) {
  4.     if(a < b) return b;
  5.     return a;
  6. }
  7. int main() {
  8.     int A, B;
  9.     scanf("%d%d", &A , &B);
  10.     int k;
  11.     scanf("%d", &k);
  12.     int zbir = 0;
  13.    
  14.     for(int broj = A; broj <= B; broj++) { // za site broevi od A do B
  15.         int deliteli_na_ovoj_broj = 0;
  16.         int dali_e_k_deliv = 1;
  17.         for(int deliteli = 1; deliteli <= broj; deliteli++) {
  18.             if(broj % deliteli == 0) { // i e delitel na broj
  19.                 deliteli_na_ovoj_broj += 1;
  20.             }
  21.         }
  22.         for(int n = max(broj - k, 1); n <= broj - 1; n++) { // za sekoj brojac n, taka sto n zapocnuva od n - k, i odi do n - 1
  23.             int broj_na_deliteli = 0;
  24.             for(int deliteli = 1; deliteli <= n; deliteli++) {
  25.                 if(n % deliteli == 0) {
  26.                     broj_na_deliteli += 1;
  27.                 }
  28.             }
  29.             if(deliteli_na_ovoj_broj <= broj_na_deliteli) {
  30.                 dali_e_k_deliv = 0;
  31.                 break;
  32.             }
  33.         }
  34.         if(dali_e_k_deliv == 1) {
  35.             printf("%d\n", broj);
  36.             zbir += broj;
  37.         }
  38.     }
  39.     printf("%d\n", zbir);
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment