Advertisement
Riposati

Untitled

Dec 5th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int calcula_fatorial_iterativo(int n){
  5.  
  6.     int i,fat=1;
  7.     for(i=n-1;i>=fat;i--){
  8.         n*=i;
  9.     }
  10.     return n;
  11. }
  12.  
  13. int main()
  14. {
  15.     int n,i,aux=1,aux2=0;
  16.     int aux3 =0;
  17.  
  18.     scanf("%d",&n);
  19.     int vet[n];
  20.  
  21.     for(i=0;i<n;i++){
  22.         vet[i] = 0;
  23.     }
  24.  
  25.     for(i=0;(i<n) && (aux2<=n);i++){
  26.         aux2 = calcula_fatorial_iterativo(aux);
  27.         vet[i] = aux2;
  28.         aux++;
  29.     }
  30.  
  31.     int t=0,maior=0,j,cont=0;
  32.     for(i=0;i<n;i++){
  33.  
  34.         if(vet[i] <= n && vet[i]!=0){ /// aqui Γ© pra olhar so atΓ© o valores de fatoriais possiveis
  35.  
  36.             while(n > 0){
  37.  
  38.                 maior = vet[0];
  39.  
  40.                 for(j=0;j<n;j++){
  41.                     if(vet[j] > maior && vet[j] <= n){
  42.                         maior = vet[j];
  43.                     }
  44.                 }
  45.                 n-=maior;
  46.                 cont++;
  47.             }
  48.         }
  49.     }
  50.  
  51.     printf("%d\n",cont);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement