Advertisement
Stoycho_KK

Untitled

Oct 22nd, 2021
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #pragma warning (disable : 4996)
  2.  
  3. #include<stdlib.h>
  4. #include<stdio.h>
  5.  
  6. int cnt = 0;
  7.  
  8. void allSums(int arr[], int l, int r, int sum, const int num) {
  9.     if (l > r) {
  10.         if (sum == num)
  11.             ++cnt;
  12.         return;
  13.     }
  14.     allSums(arr, l + 1, r, sum + arr[l], num);
  15.     allSums(arr, l + 1, r, sum, num);
  16. }
  17.  
  18. int main(int argc, char* argv[]) {
  19.     int numberInput, divisor = 1, index = 0, sum = 0;
  20.  
  21.     scanf("%d", &numberInput);
  22.     int numOfDivs = 0;
  23.  
  24.     while (divisor <= numberInput / 2) {
  25.         if (numberInput % divisor == 0) {
  26.             numOfDivs++;
  27.         }
  28.         divisor++;
  29.     }
  30.  
  31.     int* arr = (int)malloc(sizeof(int) * numOfDivs);
  32.  
  33.     for (int i = 0; i < numOfDivs; i++)
  34.         arr[i] = 0;
  35.    
  36.     divisor = 1;
  37.  
  38.     while (divisor <= numberInput / 2) {
  39.         if (numberInput % divisor == 0) {
  40.             arr[index] = divisor;
  41.             index++;
  42.         }
  43.         divisor++;
  44.     }
  45.  
  46.     allSums(arr, 0, numOfDivs - 1, sum, numberInput);
  47.  
  48.     printf("%d", cnt);
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement