#include #include #include #include typedef struct node { unsigned long long n; struct node* next; } node; typedef struct node* Node; Node newNode (int n); Node append (Node head, Node n); void printList (Node head); int main() { int a, b, t; scanf("%d %d %d", &a, &b, &t); Node head = malloc(sizeof(node)); head->n = 1; head->next = NULL; unsigned long long values = 1; for (int i = 0; i < t; i++){ values *= 2; //printList(head); Node expanding = head; head = NULL; while (expanding != NULL){ head = append(head, newNode(expanding->n * a)); head = append(head, newNode(expanding->n * b)); expanding = expanding->next; } } //printList(head); unsigned long long expected = 0; while (head != NULL){ expected += head->n; head = head ->next; } printf("%llu\n", expected / values); return 0; } Node newNode (int n){ Node new = malloc(sizeof(node)); new->next = NULL; new->n = n; return new; } Node append (Node head, Node n){ if (head){ while (head->next != NULL){ head = head->next; } head->next = n; } else { head = n; } return head; } void printList (Node head){ while (head != NULL){ printf("%llu->", head->n); head = head->next; } printf("X\n"); }