fork download
  1. #include <stdio.h>
  2.  
  3. void power3(unsigned long result[]);
  4. void print_result(unsigned long result[]);
  5. int main(void) {
  6.  
  7. unsigned long result[8]={1,0,0,0,0,0,0,0};
  8. for(int n=1; n<31; n++){
  9. printf("n=%d: ",n);
  10. power3(result);
  11. print_result(result);
  12. }
  13. return 0;
  14.  
  15. }
  16.  
  17. void power3(unsigned long result[]){
  18. int i=0,j=7;
  19.  
  20. for(i; i<8; i++){
  21. result[i]*=3;
  22. }
  23. for(j; j>=0; j--){
  24. if(result[7]>9999999){
  25. result[j+1]=result[j]/100000000000000000000000000000000000000000000000000000000;
  26. result[j+1]+=0;
  27. }
  28. if(result[6]>9999999){
  29. result[j+1]=result[j]/10000000000000000000000000000000000000000000000000;
  30. result[j+1]+=0;
  31. }
  32. if(result[5]>9999999){
  33. result[j+1]=result[j]/1000000000000000000000000000000000000000000;
  34. result[j+1]+=0;
  35. }
  36. if(result[4]>9999999){
  37. result[j+1]=result[j]/100000000000000000000000000000000000;
  38. result[j+1]+=0;
  39. }
  40. if(result[3]>9999999){
  41. result[j+1]=result[j]/10000000000000000000000000000;
  42. result[j+1]+=0;
  43. }
  44. if(result[2]>9999999){
  45. result[j+1]=result[j]/1000000000000000000000;
  46. result[j+1]+=0;
  47. }
  48. if(result[1]>9999999){
  49. result[j+1]=result[j]/100000000000000;
  50. result[j+1]+=0;
  51. }
  52. if(result[0]>9999999){
  53. result[j+1]=result[j]/10000000;
  54. result[j+1]+=0;
  55. }
  56. }
  57.  
  58. }
  59.  
  60. void print_result(unsigned long result[]){
  61.  
  62. for(int i=7; i>=0; i--){
  63. if(result[i]>9999999)
  64. printf("%lu",result[i]-result[i+1]*10000000);
  65. else if(result[i]>0){
  66. printf("%lu ",result[i]);
  67. }
  68. }
  69. printf("\n");
  70. }
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
n=1:       3 
n=2:       9 
n=3:       27 
n=4:       81 
n=5:       243 
n=6:       729 
n=7:       2187 
n=8:       6561 
n=9:       19683 
n=10:       59049 
n=11:       177147 
n=12:       531441 
n=13:       1594323 
n=14:       4782969 
n=15:       1 4348907
n=16:       4 3046721
n=17:       12 9140163
n=18:       38 7420489
n=19:       116 2261467
n=20:       348 6784401
n=21:       1046 353203
n=22:       3138 1059609
n=23:       9414 3178827
n=24:       28242 9536481
n=25:       84728 8609443
n=26:       254186 5828329
n=27:       762559 7484987
n=28:       2287679 2454961
n=29:       6863037 7364883
n=30:       2 5891132094649