#include <stdio.h>
#include <stdlib.h>
#include <math.h>

// 構造体定義（課題1と同様）
typedef struct Node {
    long long prime;
    int exponent;
    struct Node* next;
} Node;

// リストの情報から約数の個数と総和を求めて表示する関数
void calculateDivisors(Node* head) {
    long long totalCount = 1; // 個数の積の初期値
    long long totalSum = 1;   // 総和の積の初期値
    Node* current = head;

    while (current != NULL) {
        // 1. 約数の個数の計算: (各指数の数 + 1) を掛け合わせる
        totalCount *= (current->exponent + 1);

        // 2. 約数の総和の計算: 等比数列の和の公式を掛け合わせる
        // 分子: p^(e+1) - 1
        long long numerator = (long long)pow(current->prime, current->exponent + 1) - 1;
        // 分母: p - 1
        long long denominator = current->prime - 1;
        
        totalSum *= (numerator / denominator);

        current = current->next; // 次のノードへ移動
    }

    printf("約数の個数: %lld 個\n", totalCount);
    printf("約数の総和: %lld\n", totalSum);
}

// ※動作確認用のメイン関数（手動でリストを構築してテスト）
int main() {
    // 例として 12 = 2^2 * 3^1 (約数は1,2,3,4,6,12の6個、和は28)
    Node* n1 = (Node*)malloc(sizeof(Node));
    Node* n2 = (Node*)malloc(sizeof(Node));
    
    n1->prime = 2;  n1->exponent = 2;  n1->next = n2;
    n2->prime = 3;  n2->exponent = 1;  n2->next = NULL;

    calculateDivisors(n1);

    free(n1);
    free(n2);
    return 0;
}