Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///BISMILLAHIR-RAHMANIR-RAHIM
- #include <stdio.h>
- #include <string.h>
- #define max 3000
- #define tot 1001
- char facto[1001][max + 1];
- char serial_str[tot][5];
- char one[] = "0001";
- void create_serial_string(int x)
- {
- int i, j;
- int sum = 0, carry = 0, temp;
- for(i = 3; i >= 0; i--){
- temp = serial_str[x - 1][i] + one[i] - '0' - '0' + carry;
- sum = temp % 10;
- carry = temp / 10;
- serial_str[x][i] = sum + '0';
- }
- serial_str[x][4] = '\0';
- }
- void serial_maker()
- {
- int i, j;
- for(i = 0; i < tot; i++){
- for(j = 0; j < 4; j++){
- serial_str[i][j] = '0';
- }
- }
- for(i = 1; i < tot; i++){
- create_serial_string(i);
- }
- }
- void build_zero_string()
- {
- int i, j;
- for(i = 0; i <= 1000; i++){
- for(j = 0; j < max; j++){
- facto[i][j] = '0';
- }
- }
- }
- void multiply_and_create_new_facto(int k)
- {
- int product, carry = 0, character;
- int i, j, l = 0;
- for(j = 3, l = 1; j >= 0; j--, l++){
- carry = 0;
- for(i = max - 1; i >= 3; i--){
- product = (int)(facto[k - 1][i] - '0') * (int)(serial_str[k][j] - '0') + carry + facto[k][i - l + 1] - '0';
- carry = product / 10;
- character = (product % 10) + '0';
- facto[k][i - l + 1] = character;
- }
- }
- facto[k][max] = '\0';
- }
- void instruct_to_create_fibo()
- {
- facto[0][max - 1] = '1', facto[0][max] = '\0';
- facto[1][max - 1] = '1', facto[1][max] = '\0';
- for(int i = 2; i <= 1000; i++){
- multiply_and_create_new_facto(i);
- }
- }
- int main()
- {
- serial_maker();
- build_zero_string();
- instruct_to_create_fibo();
- int n, i, j;
- while(scanf("%d", &n) == 1){
- printf("%d!\n", n);
- for(i = 0; i < max; i++){
- if(facto[n][i] != '0'){
- for(j = i; j < max; j++){
- printf("%c", facto[n][j]);
- }
- printf("\n");
- break;
- }
- }
- }
- return 0;
- }
- ///ALHAMDULILLAH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement