Skip to content

Instantly share code, notes, and snippets.

@8ashred8
Created May 19, 2014 07:01
Show Gist options
  • Save 8ashred8/6f2fa76202efd08503c0 to your computer and use it in GitHub Desktop.
Save 8ashred8/6f2fa76202efd08503c0 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#define N 81
/* N: 長桁計算に用意する桁数 */
int main(int argc, char *argv[]){
char a[N],b[N],p[N];
int x,i,m;
m=1;
scanf("%d",&x);
for(i=0; i!=N; i=i+1){a[i]=p[i]=0;}
a[0]=1;
while(1){
for(i=0; i!=N; i=i+1){b[i]=a[i];}
a[0]=m*a[0];
p[0]=a[0]/10;
a[0]=a[0]-10*p[0];
for(i=0; i!=N; i=i+1){
a[i+1]=m*a[i+1]+p[i];
p[i+1]=a[i+1]/10;
a[i+1]=a[i+1]-10*p[i+1];
}
for(i=0; i!=N; i=i+1){p[i]=0;}
m=m+1;
if(a[x]!=0){break;}
}
for(i=N; i!=1 && b[i-1]==0; i= i-1) printf("");
/* 残りの桁を数字列として書き出す */
while( i!=0 ){ printf("%1d", b[i-1]); i= i-1;}
/*改行*/
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment