#include <stdio.h>

int eh_primo(int x){
    int i, p=0;
    for(i=1; i<=x; i++){
        if(x%i==0){
            p++;
        }
    }
    if(p==2){
        return 1;
    }else{
        return 0;
    }
}

int proximo_primo(int x){
    while(eh_primo(x)!=1){
        x+=1;
    }
    return x;
}

int fatorial(int x){
    int i, fat=1;
    for(i=1; i<=x; i++){
        fat*=i;
    }
    return fat;
}

int main() {
    int n, x;
    double total=0;
    scanf("%d", &n);
    for(x=1; x<=n; x++){
        if(x==1 || eh_primo(x)==1){
            printf("%d!/%d", x, x);
            total+=fatorial(x)/x;
        }else{
            printf("%d!/%d", x, proximo_primo(x));
            total+=fatorial(x)/proximo_primo(x);
        }
        if(x<=n-1){
            printf(" + ");
        }
    }
    printf("\n%.2lf\n", total);
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: