Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning (disable : 4996)
- #include<stdlib.h>
- #include<stdio.h>
- int cnt = 0;
- void allSums(int arr[], int l, int r, int sum, const int num) {
- if (l > r) {
- if (sum == num)
- ++cnt;
- return;
- }
- allSums(arr, l + 1, r, sum + arr[l], num);
- allSums(arr, l + 1, r, sum, num);
- }
- int main(int argc, char* argv[]) {
- int numberInput, divisor = 1, index = 0, sum = 0;
- scanf("%d", &numberInput);
- int numOfDivs = 0;
- while (divisor <= numberInput / 2) {
- if (numberInput % divisor == 0) {
- numOfDivs++;
- }
- divisor++;
- }
- int* arr = (int)malloc(sizeof(int) * numOfDivs);
- for (int i = 0; i < numOfDivs; i++)
- arr[i] = 0;
- divisor = 1;
- while (divisor <= numberInput / 2) {
- if (numberInput % divisor == 0) {
- arr[index] = divisor;
- index++;
- }
- divisor++;
- }
- allSums(arr, 0, numOfDivs - 1, sum, numberInput);
- printf("%d", cnt);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement