Advertisement
Riposati

Untitled

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