You are not logged in. Please login at www.codechef.com to post your questions!

×

Small Factorial, I tested my solution against WOLFRAM ALPHA but still wrong answer!!

http://www.codechef.com/viewsolution/6569544

here is my solution. I've checked as many possible cases I can but no use, still WA.

asked 23 Mar '15, 03:23

nb333's gravatar image

0★nb333
11
accept rate: 0%

edited 23 Mar '15, 03:33

It is giving the right answer for all the numbers between 1->100, also i've put 0!=1. Plzz help i've been on it for 12 hrs now....

(23 Mar '15, 03:25) nb3330★

#include<stdio.h>

include<stdlib.h>

define MAX 500

////////////////////////////////////////////// int multiply(int *k,int num,int size) {

int carry=0,i,j,n; for(i=0;i<size;i++) { j=k[i]; k[i]=((jnum)+carry)%10; carry=((numj)+carry)/10;

}

n=carry; while(carry/10!=0) { k[i]=carry%10; carry=carry/10; i++; } k[i]=carry; ++i;

return i; }

///////////////////////////////////////////////// int fill(int k,int num) { if(num/10==0) {k[0]=num;return 1;} else if(num==100) {k[0]=0;k[1]=0;k[2]=1;return 3;} else {k[0]=num%10;k[1]=num/10;return 2;} } ////////////////////////////////////////////////// void display(int k,int size) { //printf("\n"); //printf("Display\n"); int j; for(j=size-1;j>=0;j--) { printf("%d",k[j]); } } ///////////////////////////////////////////////// void fact(int n,int fac) { //printf("Fact\n"); int i,j,num,k,temp,adder,size,foo; num=n; if(n%2==0) {j=num/2;foo=0;} else {j=num/2+1;foo=1;} k=(int *)calloc(j,sizeof(int)); temp=0;adder=num; if(foo==0) { for(i=0;i<j;i++) { k[i]=num+temp; adder=adder-2; temp=adder; num=k[i]; } } else { for(i=0;i<j-1;i++) { k[i]=num+temp; adder=adder-2; temp=adder; num=k[i]; } k[i]=j; }

size=fill(&fac[0],k[0]);

for(i=1;i<j;i++) size=multiply(&fac[0],k[i],size); display(&fac[0],size); }

int main() {

int *k,i,j,n,num,t;

int fac[MAX];

scanf("%d",&t);

for(i=0;i<t;i++) { scanf("%d",&n); if(n==0){printf("%d\n",1);continue;} fact(n,&fac[0]); printf("\n"); } return 0; }

link

answered 23 Mar '15, 03:38

nb333's gravatar image

0★nb333
11
accept rate: 0%

this is my code .

(23 Mar '15, 03:38) nb3330★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×83
×46
×33
×5

question asked: 23 Mar '15, 03:23

question was seen: 912 times

last updated: 23 Mar '15, 03:38