CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February Long Contest
    • January CookOff
    • January Long Contest
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Small factorials

Small factorials

Problem code: FCTRL2

  • Submit
  • All Submissions

All submissions for this problem are available.

A tutorial for this problem is available here

You are asked to calculate factorials of some small positive integers.

Input

An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

Output

For each integer n given at input, display a line with the value of n!

Example

Sample input:
4
1
2
5
3

Sample output:

1
2
120
6


Date: 2008-12-01
Time limit: 1

s
Source limit: 2000
Languages: C C99 strict C++ PAS gpc PAS fpc JAVA NICE JAR C# C#2 NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp HASK CAML CLPS PRLG WSPC BF ICK


  • Submit

Comments

  • Login or Register to post a comment.

rushto_siva @ 21 May 2009 11:48 PM

Is it possible to know the reason why my code failed? And would also like to know the input for which it failed. I ran in my PC with the sample input and it worked fine.

skydiploma @ 27 May 2009 05:56 PM

The main Issue I am having is the Space management for a particular number.

most probably int will not be able to handle the factorial of 100 or 99
Is it okay if a double is returned?

deepakvsoni @ 29 May 2009 06:25 PM

Can you please tell the reason my code failed? I tested it with the sample input and got the output matching the sample out given.

manmath @ 5 Jun 2009 09:12 PM

Can you please tell the reason my code failed? I tested it with the sample input and got the output matching the sample out given.

leppyr64 @ 6 Jun 2009 06:14 AM

@manmath - do you get the correct solution for 100?

amit_uiet @ 7 Jun 2009 09:06 AM

hey... what wrong with code?
Even I have checked for 100 it give correct result.....

walson_dias @ 7 Jun 2009 07:17 PM

Someone plz give me the link to get the compiler (gcc g ) which codechef uses. My programs run pretty well with Turbo C but here they seem to give compilation error.

saurabhh @ 12 Jun 2009 04:55 AM

Have checked my code like a hundred times but to no use.

arun_mittal @ 13 Jun 2009 09:00 AM

from where can i het the correct solution

sanjay_ankur @ 14 Jun 2009 04:10 AM

looks like a lot of us have the same problem. is it because of something like a stack usage limit or something?? admins please help?

saurabhh @ 19 Jun 2009 09:47 PM

seems like a lot of ppl have problem with handling very large nos.

meowmix @ 21 Jun 2009 06:26 PM

HAHAHAHAHA! Freaking java bigint :|

mecrazycoder @ 3 Jul 2009 07:19 PM

use warnings;
use strict;
my $fact=1;
my $no;
my $j;
$no=<STDIN>;
while($no)
{
$j=<STDIN>;
while($j)
{
$fact=$fact*$j--;
}
print $fact."\n";
$fact=1;
$no--;
}
Whats wrong with my perl code

dragonair @ 5 Jul 2009 05:39 AM

>:( this is not gud :( i chked it a lotta times and itz not working :(( here is the code i entered:-

#include<iostream.h>

long int factorial(int n){

if(n<=1){
return(n);
}
else{
n=n*factorial(n-1);
return(n);
}
}

int main(){
int i,*arr,j,fact;
cin>>i;
if(i<=1

i0exception @ 6 Jul 2009 05:12 PM

@all A tutorial for this problem has been added under the help section.

mrsaturns @ 10 Jul 2009 03:33 AM

Mine too. It works perfectly, but it won't accept it.

i0exception @ 10 Jul 2009 05:25 PM

If it is not being accepted, then it means that there is something wrong with your code. Check the tutorial for more details. http://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/

pankajss @ 26 Jul 2009 02:18 AM

If factorial is defined as double and returns answer with nill trailing zeroes is it wrong?

admin 2 @ 26 Jul 2009 07:56 AM

Could you be more specific?

pankajss @ 26 Jul 2009 08:46 AM

@admin:- Actually i meant, factorial which is 1x2x3x4....., what if i store factorial as double (that way it could store larger values).

But sorry admin, i got it, It would give wrong answer that way and i have to store it as an integer.

I finally managed this one. Tutorial helped alot.

Thanks

gaurav17 @ 26 Jul 2009 08:47 PM

its running ok on my pc..

gaurav17 @ 26 Jul 2009 08:48 PM

then how cud it be wrong

admin 2 @ 26 Jul 2009 10:19 PM

@gaurav You might want to take a look at the tutorial for this problem.

rohanbk @ 8 Aug 2009 08:44 PM

Wow, dealing with BigInts in Java is really annoying.

Can I know why my code

nitin_directi @ 18 Aug 2009 11:53 PM
Can I know why my code fails I have made code according to the tutorial

You can try testing it on few

admin @ 19 Aug 2009 02:29 AM

You can try testing it on few large values and calculating the answer using the calculator accessory in your operating system.

im gettin result on my system

raviteja6771 @ 19 Aug 2009 08:16 PM
im gettin result on my system but here its saying time limit exceeded...??? i used the algol given in http://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/ why is not working ??? plz reply....:(

@ravi Check your usage of the

admin @ 20 Aug 2009 01:37 AM

@ravi Check your usage of the variable 'j' . You are using it again within the loop where you have used it first.

hi, this is the output of my

vpraveen @ 26 Aug 2009 02:12 PM
hi, this is the output of my program, is there a formatting problem? 3 2 2 3 6 4 24 i get a runtime error on submission

The numbers in my previous

vpraveen @ 26 Aug 2009 02:14 PM
The numbers in my previous comment are in new lines.

No, the output should contain

admin @ 26 Aug 2009 02:17 PM

No, the output should contain one number on one line which. The number on line 'i' is the answer for test case 'i'

hey, the tutorial is really

anishvijay @ 27 Aug 2009 02:48 AM
hey, the tutorial is really good. So, anyone with a problem can refer to the tutorials. It works well with that concept. :) http://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/

hey y is my code not accepted

ankit4284 @ 27 Aug 2009 08:13 PM

hey y is my code not accepted plzz is there something wrong with the compiler

 

plzz se to it i tried it a number of times my code is as follows

 

 

#include<stdio.h>
#include<conio.h>

void fact(int num);
void main()
{
 int t;
 static int arr[100];
 int i;
 clrscr();

 printf("nPlz enter the number of test cases: ");
 scanf("%d",&t);

 for(i=0;i<t;i++)
 {
  scanf("%d",&arr[i]);
 }

 for(i=0;i<t;i++)
 {
  fact(arr[i]);
 }

 getch();

}


void fact(int num)
{
 int i;
 long int fact1=1;

 for(i=1;i<=num;i++)
 {
  fact1=fact1*i;

 }
 printf("n%ld",fact1);
}

hey there's no wrong in the

ankit4284 @ 27 Aug 2009 08:20 PM

hey there's no wrong in the above solution so y is it not accepted

 

There is a tutorial for this

admin @ 27 Aug 2009 10:01 PM

There is a tutorial for this problem at http://blog.codechef.com/2009/07/02/tutorial-for-small-factorials/ A long integer cannot store something like 100!

i think this will run very

sridarshan @ 29 Aug 2009 10:43 PM

i think this will run very well in python because

there is no limit to size of the numbers

whereas in c++ the maximum we can represent is 4000000000somethin

what if the input is greated

hims_shashi @ 3 Sep 2009 12:45 PM

what if the input is greated than 100. for example :

Input : 3

            5

            200

            100

Just let me know the output of the above input.

 

 

The input specifications

admin @ 3 Sep 2009 01:08 PM

The input specifications clearly state that the value of n will be 100 at max.

void main() { int

baby @ 5 Sep 2009 05:57 PM

void main()

{

int i,n,fact=1;

scanf("%d",n);

for(i=1;i<=n;I++)

printf("%dn",i);

for(i=1;i<=

print

def fact(n) if n < 100   if n

tvsbpkumar @ 8 Sep 2009 03:08 PM

def fact(n)

if n < 100
  if n == 0
    1
  else
    n * fact(n-1)
  end

else

 puts "Number should less than 100 ..."

end
end

 wat do we have to do??????

sankalpasawa @ 13 Sep 2009 10:21 PM

 wat do we have to do??????

 how do i store 100 ! in

kartikeya1994 @ 13 Sep 2009 11:27 PM

 how do i store 100 ! in java?...

 

im a school student learning java....guess i'll need a little help at this...im getting the code right but do not know how to store larger values

hi.. My code ran succesfully

rakshith_babu @ 14 Sep 2009 09:39 PM

hi..

My code ran succesfully on the same compiler on dev cpp...

it gave correct answer even for 100!. But i'm getting wrong answer on code chef...

plz help out.. can u plz have a look at my code also..

sorry.. i got the bug.

rakshith_babu @ 14 Sep 2009 10:09 PM

sorry..

i got the bug.

My code is showing the wrong

mkd_16 @ 17 Sep 2009 07:28 AM
My code is showing the wrong answer but im getting the right ones even for 100 when i test, Im using python so dont see why it wont work

Is your output format in

admin @ 17 Sep 2009 01:55 PM
Is your output format in accordance with the one mentioned in the problem statement?

Yes it was lol i got the

mkd_16 @ 18 Sep 2009 02:19 AM
Yes it was lol i got the answer, just an obvious mistake of not making the function call after writing the function, ridiculous! Mostly my inexperience with Python.

# include

nitin14 @ 18 Sep 2009 10:52 PM
# include # include void main(){ int n; int f=1; clrscr(); printf("enter hte number whos factorial is being calculated"); scanf("%d",&n); while(n>0){ f=f*n; n--;} printf("the factorial of number %d is %d",n,f); getch();}

its so simple & easy to

nitin14 @ 18 Sep 2009 10:53 PM
its so simple & easy to understand for beginners

simple & easy to understand

nitin14 @ 18 Sep 2009 11:20 PM
simple & easy to understand # include # include void main(){ double n;/* variable of datatype double*/ double f=1;/* initialize a vcariable of datatype double by 1*/ clrscr(); printf("enter the number whose factorial is being calculated"); scanf("%lf",&n); double i=n; while(n>0){ f=f*n; n--;} printf("the factorial of number %lf is %lf",i,f); getch();}

Hey people please check out

rahul142 @ 20 Sep 2009 11:30 PM
Hey people please check out my code. Its working fine with the sample input. public class Main { public static void main(String[] args)throws java.lang.Exception { java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); int t = Integer.parseInt(in.readLine()); int fact = 1; int a[] = new int[t]; for(int i = 0;i

hi..i have made the code..it

scorpion @ 21 Sep 2009 12:36 PM
hi..i have made the code..it got submitted earlier but i got runtime error... but now after rectification of the same its not even gettin submitted ..its saying your code length is more than 2000 bytes...

Yes, your source code length

admin @ 21 Sep 2009 01:44 PM
Yes, your source code length should be less than 2000bytes

I have submitted dis

mayanksolanki6 @ 23 Sep 2009 12:17 AM

I have submitted dis solution

#include<stdio.h>

#include<conio.h>

int factorial(int val)

{

int i,res=1;

for(i=1;i<=val;i++)

{

res=res*i;

}

return res;

}

 

void main()

{

int i,n,val,fact;

clrscr();

printf("nPlease enter no of inputs:");

scanf("%d",&n);

for(i=0;i<n;i++)

{

printf("nEnter value:");

scanf("%d",&val);

fact=factorial(val);

printf("%d",fact);

}

getch();

}

on my computer i am getting correct answer, why admin is showing compilation error for my code.

Please read the FAQ. don't

admin @ 23 Sep 2009 12:47 AM

Please read the FAQ. don't use conio.h and getch(). main should return an integer value and your program should end with a return 0

I wrote program which takes

sumeetkumar001 @ 28 Sep 2009 07:28 PM
I wrote program which takes command line argument

it is working but still it

sumeetkumar001 @ 28 Sep 2009 07:29 PM
it is working but still it shows here wrong answer

You need to take input from

admin @ 28 Sep 2009 07:32 PM

You need to take input from stdin and output the results to stdout.

gud eve admin.. i have run my

braintorrent @ 30 Sep 2009 09:18 PM
gud eve admin.. i have run my code many times and it's producing the same output as desired.. so what has really been the problem in my code?? #include int main() { int l=0,n=0,i,f=1,j; scanf("%d",&l); for(i=1;i<=l;i++) { scanf("%d",&n); for(j=1;j<=n;j++) { f*=j; } printf("%dn",f); f=1; } return(0); }

The first thing you should

triplem @ 1 Oct 2009 06:02 AM

The first thing you should have tested your program on was an input of 100.. you obviously haven't.

thnx admin..

braintorrent @ 1 Oct 2009 11:36 PM
thnx admin..

(define factorial (lambda (x)

kaitokai @ 2 Oct 2009 11:29 PM

(define factorial
(lambda (x)
(if (> x 1)
(* x (factorial (- x 1)))
1 )))

 

What's wrong with this scheme code? it gives the correct output for all integers.

can anyone paste ur code

sai anusha @ 3 Oct 2009 11:43 AM

can anyone paste ur code here.........plz

can someone tell me where i

rampage @ 16 Oct 2009 02:32 PM

can someone tell me where i am going wrong?

i am generating this output :

50

30414093201713378043612608166064768844377641568960

512000000000000

 

100

933262154439441526816992388562667004907159682643

816214685929638952175999932299156089414639761565

182862536979208272237582511852109168640000000000

00000000000000

 

this is the code of my

rampage @ 16 Oct 2009 03:49 PM

this is the code of my program

#include<iostream.h>

int main()

{

int t,n,fact[200],i,j,k,c,temp,x;

cin>>t;

for(i=0;i<t;i++)

{

cin>>n;

c=n;

j=0;

while(c>0)

{

fact[j]=c%10;

c=c/10;

j++;

}

while(n>1)

{

n--;

temp=0;

for(k=0;k<j;k++)

{

x=fact[k]*n+temp;

fact[k]=(x%10);

temp=x/10;

if(k==j-1)

{

while(temp>0)

{

fact[j]=temp%10;

temp=temp/10;

j++;

}

break;

}

}

}

for(k=j-1;k>=0;k--)

cout<<fact[k];

}

return 0;

}

 

 

 

 

 

Run your code on the sample

triplem @ 16 Oct 2009 04:23 PM

Run your code on the sample input and look at what you get as output.

had missed the newline

rampage @ 16 Oct 2009 04:30 PM

had missed the newline .....

thnx:)

where can i see the reference

bezgin @ 18 Oct 2009 08:17 AM

where can i see the reference output to an input that contains all numbers 0-100?

My code seems to run perfect, i want to find the bug!!!

Wow! Check out the ones at

bezgin @ 18 Oct 2009 08:58 AM

Wow! Check out the ones at the end. Nice problem, never thought it'd be this challenging

check out the zeroes, i mean

bezgin @ 18 Oct 2009 08:58 AM

check out the zeroes, i mean

Well can any of u plz tell me

Game_Bit @ 22 Oct 2009 01:09 AM

Well can any of u plz tell me why this code isnt able to calculate more than 33! the values before 33! are correct......im a bit puzzled....plz help thanks

 

vector< vector<int> > V;
vector<int> v;
v.push_back(1);V.push_back(v);v.clear();
for(i=1;i<=100;i++)
{
temp = 0;v.clear();
l = V[i-1].size();
for(j=0;j<l;j++)
{
val = V[i-1][j]*i+temp;
v.push_back(val%10);
temp = val/10;
}
if(temp != 0) v.push_back(temp);
V.push_back(v);
}

Lol bigint worked great!!

JoeVaulter @ 22 Oct 2009 09:14 AM

Lol bigint worked great!! java isnt that bad. Should try it with the arrays though. Is it faster that way

somebody tell me why my code

ansu @ 30 Oct 2009 01:28 AM

somebody tell me why my code is not working..

when i'm running on my pc..it is showing correct output..

 

import java.util.*;
public class Main {

/**
* Creates a new instance of <code>Main</code>.
*/
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner input = new Scanner(System.in);
int t=input.nextInt();
int x[]=new int[t];
for(int i=0;i<t;i++)
x[i]=input.nextInt();

for( int i=0;i<t;i++)
{
System.out.printf("%dn",fact(x[i]));
}



}
public static int fact(int n)
{
if(n==0 )
return 1;
else
return n*fact(n-1);

}
}

You obviously haven't tested

triplem @ 30 Oct 2009 02:02 AM

You obviously haven't tested your code on any large inputs. Read the constraints again.

i have solved Small Fractions

mayanksolanki6 @ 17 Nov 2009 11:46 PM

i have solved Small Fractions problem many times on my machine bt when i have submitted its givin run time error problem wh so??

Infact i did coding on the online compiler as well .

Please help as da prog is workin fine.

pls answer it admin

mayanksolanki6 @ 18 Nov 2009 01:35 PM

pls answer it admin

Go to

triplem @ 18 Nov 2009 02:13 PM

Go to http://www.codechef.com/wiki/. In particular read the Status Codes section, though you should also read the FAQ.

dis is my code for small

mayanksolanki6 @ 18 Nov 2009 09:54 PM

dis is my code for small factorial when i submitted its givin wrong answer why???

  1. /*Program for small factorial in C by Mayank Solanki*/
  2. #include<stdio.h>
  3.  
  4. int main()
  5. {
  6. int no,n,fact=1,i,j;
  7. printf("nEnter total no for which you want to find factorial:");
  8. scanf("%d",&n);
  9. if(n>100 || n==0)
  10. {
  11. printf("nNo should be 1<=n<=100");
  12. }
  13. else
  14. {
  15. for(i=0;i<n;i++)
  16. {
  17. fact=1;
  18. printf("nEnter no:");
  19. scanf("%d",&no);
  20. for(j=1;j<no;j++)
  21. {
  22. fact=fact*j;
  23. }
  24. printf("nFactorial for %d is %d",no,fact);
  25. }
  26. }
  27.  
  28. return 0;
  29. }
Admin pls tell me my code is workin fine with my machine.
pls tell me..........

It is not working fine on

triplem @ 19 Nov 2009 04:32 AM

It is not working fine on your machine. Firstly, it is printing out things that shouldn't appear in the output. You have to print exactly what it tells you to print and nothing else.

Secondly, it isn't even giving the right output for the sample input. In fact it gives the wrong answer for every single input.

And lastly, the input could be up to 100. You obviously haven't tested it on an input of this size.

Hai Smerity, how's life? (:

cheshire @ 19 Nov 2009 06:06 AM

Hai Smerity, how's life? (:

as a completely unrelated,

cheshire @ 19 Nov 2009 06:12 AM

as a completely unrelated, there seems to be an interesting trend - people who can't write in a human language can't write in a programming language as well.

This is my pgm its working

vinopavit @ 30 Nov 2009 12:53 PM

This is my pgm its working upto 15 numbers but not working beyond that

so please help me

#include<stdio.h>
int main()
{
unsigned int fact=1;
int t,n,i;
scanf("%d",&t);
while(t!=0)
{
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("n%u",fact);
t--;
fact=1;
}

}

You already found the problem

triplem @ 30 Nov 2009 01:00 PM

You already found the problem yourself. Why isn't it working for anything greater? Because an unsigned int cannot hold the result. You need something that will work for much bigger numbers.

don't use this library

amit.hak50 @ 1 Dec 2009 08:09 PM

don't use this library #include<conio.h>,it is depricated in gcc or g++

#include < stdio.h >#include

new creater @ 12 Dec 2009 11:41 AM

#include < stdio.h >
#include < stdlib.h >
main()
{
 short int i, j, k, top;
 int num;
 short int *p, *ans_array;

 scanf("%d", &num);
 p = calloc(num, sizeof(short));

 for(i = 0; i < num; i++){
  scanf("%d", &k);
  p[i] = k;
 }
 for( i = 0; i < num; i++){
  ans_array = calloc(p[i] * 2, sizeof(short));
  ans_array[0] = 1;
  top = 0;
  for(j = 1; j <= p[i]; j++){
   for(k = 0; k <= top; k++)
    ans_array[k] *= j;
   for(k = 0; k < top; k++){
    if(ans_array[k] > 9){
     ans_array[k + 1] += ans_array[k] / 10;
     ans_array[k] %= 10;
    }
   }
   while(ans_array[k] > 9){
    //ans_array[k + 1] = 0;
    ans_array[k + 1] += ans_array[k] / 10;
    ans_array[k] %= 10;
    k++;
   }
   top = k;
  }
  for(k = top; k >= 0; k--)
   printf("%d", ans_array[k]);
  printf("n");
  free(ans_array);
 }
 free(p);
 return 0;
}

Please tell me what's wrong with it,it gets a Compilation Error when it runs!

thank you in advance.

It doesn't work on any input

triplem @ 17 Dec 2009 02:03 AM

It doesn't work on any input because the first thing you print out is 'enter the number' which is not part of the correct output.

It doesn't work on large inputs at all because of overflow. Haven't you tested your code?

whats wrong with this

stonecold @ 20 Dec 2009 09:20 PM

whats wrong with this code?

#include<stdio.h>

void factorial(int j)

{

int a[200]={0};

int temp,m=0,temp1,temp2=0;

temp=j;

do

{

a[m]=temp%10;

temp=temp/10;

m++;

}while(temp!=0);

j--;

temp=0;

temp2=--m;

for(;j>1;j--)

{

m=0;

do

{

temp1=(a[m]*j+temp)%10;

temp=(a[m]*j+temp)/10;

a[m]=temp1;

m++;

}while((temp!=0) || (m<=temp2));

temp2=--m;

}

 

for(;m>=0;m--)

printf("%d",a[m]);

}

 

 

int main()

{

int i,j,k=1;

scanf("%d",&i);

for(;i>0;i--)

{

scanf("%d",&j);

if(j==0)

printf("%d",k);

else

factorial(j);

}

return 0;

}

pls help.

Hi I've submitted my code but

nighthunter33 @ 21 Dec 2009 12:18 PM

Hi I've submitted my code but keep reciving a runtime error. The code works fine on my computer for all test cases. Can anyone see where it might be failing here?

 

Thanks

oops sorry, I thought this

nighthunter33 @ 21 Dec 2009 12:19 PM

oops sorry, I thought this was a pubic code solution here is my code.

 

[code]

#include <stdio.h>

int main () {
int array[150];
int results[150];
int cases=0,counter=0,counter2=0;
for(counter=0;counter<150;counter++){
results[counter]=1;
}
scanf("%d",&cases);
for(counter=0;counter<cases-1;counter++){
scanf("%dn",&array[counter]);
}
for (counter=0; counter<cases; counter++) {
for(counter2=1;counter2<=array[counter];counter2++){
results[counter]=results[counter]*counter2;
}
}
for(counter=0;counter<cases;counter++){
if(array[counter]==0){
printf("0n");
}
else {
printf("%dn",results[counter]);
}
}
}

[/code]

 

I have submited the code

anurag_aggarwal @ 26 Dec 2009 08:00 PM

I have submited the code which is working fine in my PC but i am gettign wrong answer every time

my problem ID is 154390

pls help

please tell me how to

rumi2752 @ 28 Dec 2009 02:15 PM

please tell me how to perticipate in the january algo challenge....

is it possible without forming a team?

if not , how can one form a team????

please admin  or   aniruddha   or   stephen.....

answer me..

I m getting result but on my

siddharthdevilz @ 28 Dec 2009 11:25 PM

I m getting result but on my system but each time time limit exceeded.... pls help!!!

@Mazharul: No need to form

jcomeau_ictx @ 29 Dec 2009 01:55 AM

@Mazharul: No need to form teams, in fact I don't think it's fair to do so. Once the contest starts, the problems become visible at http://www.codechef.com/JAN10/, and you solve them same as the test problems, on your own.

@jhon   thank you buddy..

rumi2752 @ 29 Dec 2009 10:12 AM

@jhon   thank you buddy..

@admin can u plzz let me knw

sumit.guha @ 31 Dec 2009 12:43 PM

@admin

can u plzz let me knw why m i getting wrong answer

i chcked the answer for 100! and it is correct

bt dont knw why is the server is saying it wrng :(

dear admin  i hv correctly

Geniusguy @ 31 Dec 2009 01:24 PM

dear admin

 i hv correctly solved the above problem by reading the tutorial 2 this problem . . .but i want to optimize the sol. by saving two digits in each array element as suggested at the last of tutorial. . .for this i have used    x%100 and x/100. . . .instead of x%10 nd x/10. . .bt the problem wid this method is that "the solution differs in number of zeroes". . . i think when a term wid two zero's come it is treated as a single zero after division. . .so please guide me tht How can i retain those zero's in my result array  ? ? ? ? ?

plzz reply at least ! ! !

Geniusguy @ 1 Jan 2010 11:41 PM

plzz reply at least ! ! !

@Ankush Keep a flag to

admin @ 1 Jan 2010 11:53 PM

@Ankush Keep a flag to specify minimum field width.

@Sumit Check for other numbers.

@Anurag Please read tutorial

This is my code i m getting

aswath78 @ 10 Jan 2010 02:42 PM

This is my code i m getting answer in my system but not here.suggest me

 

#include <iostream>

using namespace std;

long double fact(long double f);

main()

{

long double b,c[100];

int d;

std::cin>>b;

for(d=0;d<b;d++)

{

cin>>c[d];

}

for(d=0;d<b;d++)

{

c[d]=fact(c[d]);

}

for(d=0;d<b;d++)

{

std::cout<<c[d]<<"n";

}

}

long double fact(long double f)

{

long double g=f;

if(f==0)

return 1;

else

g=g*fact(f-1);

return g;

}

You aren't printing the exact

triplem @ 10 Jan 2010 03:13 PM

You aren't printing the exact answer for any input 10 or higher.. you must have only tested your program on something from 1 to 9.

Program runs fine on my

hiren.sharma @ 10 Jan 2010 05:12 PM

Program runs fine on my computer but when i submit it gives runtime error

O/P on my PC is like:

5
11
39916800
5
33720
10
1610130412800
20
573539285346655414026240000
4
24

Wats wrong Why does it Give Runtime Error

I MODIFIED MY OUTUP NOW BUT

hiren.sharma @ 10 Jan 2010 05:54 PM

I MODIFIED MY OUTUP NOW BUT STILL IT SHOWS THE SAME RUNTIME ERROR. CAN ANYONE HELP !!!!!

I DID EVERYTHING AS IT WAS MENTIONED IN THE TUTORIAL . .................PLEASE ADMIN !!!!

SHOULD I DISCLOSE THE CODE I HAVE WRITTEN HERE

MY NEW O/P IS:


5
11
5
10
20
4
39916800
33720
1610130412800
573539285346655414026240000
24

sorry got the issue. . . in

hiren.sharma @ 10 Jan 2010 06:20 PM

sorry got the issue. . . in few cases output was wrong

Please help... I've solved

rajatkhanduja @ 11 Jan 2010 12:35 AM

Please help...

I've solved many problems on this site in C language and tred my solution on both TurboC and MS Visual C++.

Now I've also tried the solution of this problem on gcc.

I'm still getting a run-time error

Your code is missing the

triplem @ 11 Jan 2010 06:08 AM

Your code is missing the required return 0.

i submitted the folling

nikhil belchada @ 11 Jan 2010 09:39 PM

i submitted the folling code,what went wrong....

using System;

class Program
{
static void Main(string[] args)
{
Int64 i = Convert.ToInt64 ( Console.ReadLine ());
Int64[] x = new Int64[i];

Int64 j;
for(  j= 0; j<=i-1; j++)
{
x[j] = Convert.ToInt64(Console.ReadLine());
Int64 fact = 1;
for (Int64 k = 1; k <= x[j]; k++)
{
fact = fact * k;

}
x[j] = fact;

}
for (Int64 dis = 0; dis <= i - 1; dis++)
{
Console.WriteLine(x[dis]);

}

}
}

You haven't tested it, have

triplem @ 12 Jan 2010 02:04 AM

You haven't tested it, have you? Test it.

ya.... it is giving proper

nikhil belchada @ 12 Jan 2010 01:17 PM

ya....

it is giving proper o/p:

No it isn't. It is failing on

triplem @ 12 Jan 2010 03:37 PM

No it isn't. It is failing on nearly every single case. What test cases did you try?

#include<stdio.h> #include<s

srvtiwari @ 16 Jan 2010 12:25 PM

#include<stdio.h>

#include<string.h>

int multiply(int array[],int i,int size)

{

int d=0,c=0;

int l=size;

int j=0;

while(j<l)

{

d=(array[j])*i+c;

array[j]=(d%10);

c=d/10;

j++;

}

if(c>0)

{

array[size++]=c%10;

c=c/10;

}

return size;

 

}

int dofactorial(int array[],int number,int size)

{

int i=1;

while(i<=number)

{

size=multiply(array,i,size);

i++;

}

for(i=size-1;i>=0;i--)

printf("%d",array[i]);

return size;

}

int main()

{

int n;

scanf("%d",&n);

int array[50];

int number;

while(n>0)

{

array[0]=1;

int size=1;

scanf("%d",&number);

size=dofactorial(array,number,size);

printf("n");

n--;

}

return 0;

}

 

i am getting correct o/p on my computer,but here its showing run time error !! why??

How big is 100! ?

triplem @ 16 Jan 2010 01:05 PM

How big is 100! ?

Hey ! plz help me   I wrote

shaurya @ 21 Jan 2010 02:22 AM

Hey ! plz help me

 

I wrote the code:

#include<stdio.h>
int main()
{
int arr[200],arrn[100];
int i,j,x,m,t,temp,index;
scanf("%d",&t);

i=0;
while(i<t)
{
scanf("%d",&arrn[i]);
i++;
}
i=0;
while(i<t)
{
m=0;
arr[0]=1;
for(j=2;j<=arrn[i];j++)
{
temp=0;      
index=0;
do
{
x=arr[index]*j+temp;
arr[index]=x%10;
temp=x/10;
index++;
}while(index<=m);
while(temp!=0)
{
m++;
arr[m]=temp;
temp=temp/10;
}  
}
i++;
while(m>=0)
{
printf("%d",arr[m]);
m--;
}
printf("n");
}
return 0;
}                                  
and it works fine on my pc. bt here wrong answer is generated.

Please read the FAQ before

triplem @ 21 Jan 2010 05:08 AM

Please read the FAQ before posting comments.

You have one small bug that is causing you to get the wrong answer for the majority of inputs. Try testing your output in more detail.

i appologise ,, and thanx

shaurya @ 21 Jan 2010 01:17 PM

i appologise ,,

and thanx

it is a nice problem.

rajesh3646 @ 26 Jan 2010 09:31 PM

it is a nice problem.

Hello Admin   May i know what

jalanvivek1987 @ 29 Jan 2010 04:20 PM

Hello Admin

 

May i know what was the problem in my latest solution( ID 174789 )

Thanks in advance

ever time my code get RTE

nap007 @ 30 Jan 2010 01:14 AM

ever time my code get RTE :::::

plz give me some INput && output

 

#include<stdio.h>

#include<string.h>

 

char a[10005][30005]; //digit require

char fac[30005]; //digit require

 

int main()

{

long hand,i,j,g,len,k,test;

 

fac[0]='1';

strcpy(a[0],fac);

len=1;

 

for(i=1;i<=1000;i++) //upper limit== digit require

{

hand=0;

for(j=0;j<len;j++)

{

hand=(fac[j]-48)*i+hand;

fac[j]=hand%10+48;

hand=hand/10;

}

while(hand!=0)

{

fac[len]=hand%10+48;

hand=hand/10;

len++;

}

fac[len]=0; // '' ASCI VALUE==0

strcpy(a[i],fac);

}

 

scanf("%ld",&test);

while(test--)

{

scanf("%ld",&k);

len=strlen(a[k]);

for(g=len-1;g>=0;g--)

printf("%c",a[k][g]);

printf("n");

}

return 0;

}

Please read the FAQ.

triplem @ 30 Jan 2010 02:05 AM

Please read the FAQ.

Hello   below is my code for

jalanvivek1987 @ 1 Feb 2010 01:02 PM

Hello

 

below is my code for which i m getting RTE but i have tested it for all 100 numbers it i sworking fine

Kindly let me know where is the mistake

 

import java.text.DecimalFormat;


class Main{

public Main() {
super();
}
public static void main(String[] args)
{
DecimalFormat formatter = new DecimalFormat("#0");
Double[] input = null;
int inputReceived = 0;
inputReceived = Integer.valueOf(args[0]);
input = new Double[inputReceived];
for(int i=0; i<inputReceived; i++){
int j = i;
j++;
input[i] = Double.valueOf(args[j]);
}
for(int k=0; k<inputReceived; k++ ){
double fact= 1;
for (int l= 1; l<=input[k]; l++){
fact=fact*l;
}
System.out.println(formatter.format(fact));
}
System.gc();       
}
}

 

Thanks in advance

Regards

Vivek

You aren't provided input

triplem @ 1 Feb 2010 01:32 PM

You aren't provided input from the command line arguments. Read the FAQ.

i am getting correct value

legendofseeker @ 3 Feb 2010 05:35 PM

i am getting correct value but still it is not accepting.

If it is not accepting then

triplem @ 4 Feb 2010 02:02 AM

If it is not accepting then you are not getting the correct value.

im getting runtime erroer and

bhavesh.j25 @ 12 Feb 2010 09:16 PM

im getting runtime erroer and one more thing when i try to change int datatype to double funtion it shows funtion should return a value

int datatype not showing factorial above 15

 

heres my code ...

 

 

#include<stdio.h>
//#include<conio.h>
int fact(int);

int main()
{
int no,f,t,i;
//clrscr();
//printf("enter the number of test cases below 15n");
scanf("%d",&t);
if(t>15)
{
return (main());
}
else
{
for(i=1;i<=t;i++)
{
// printf("nEnter Number n" );
scanf("%d",&no);
f=fact(no);
printf("%dn",f);
}
}
//    getch();
}


int fact (no)
{
int f;
if(no<=1)
return 1;
f=no*fact(no-1);
return(f);
}

Please tell your code before

triplem @ 13 Feb 2010 02:14 AM

Please tell your code before asking for help. The problems with your code will be obvious once you test it.

Stephen Merriman - 16th

muke @ 17 Feb 2010 11:16 PM

Stephen Merriman - 16th Jan,2010 13:05:56.

 

How big is 100! ?

 

my program giving me following ans for 100!

933262154439441526816992388562667004907159682643816214685929638952175999932299156894146397615651828625369792827223758251185210916864000000000000000000000000

M I right if not please reply

Stephen Merriman - 16th

muke @ 17 Feb 2010 11:16 PM

Stephen Merriman - 16th Jan,2010 13:05:56.

 

How big is 100! ?

 

my program giving me following ans for 100!

933262154439441526816992388562667004907159682643816214685929638952175999932299156894146397615651828625369792827223758251185210916864000000000000000000000000

M I right if not please reply

it seems that ans is

muke @ 17 Feb 2010 11:20 PM

it seems that ans is completely visible

its actually

100! =

933262154439441526816992388562667004907159682643816214685929638952175999932299156894146397

615651828625369792827223758251185210916864000000000000000000000000

Nearly. But not quite. You're

triplem @ 18 Feb 2010 07:40 AM

Nearly. But not quite. You're missing 2 digits somewhere in the middle.

#include<stdio.h>int fact(int

sbl @ 23 Feb 2010 02:32 AM

#include<stdio.h>
int fact(int num) {
int fac, j;
fac = 1;
for(j = 1; j <= num; j++) {
fac = fac * j;   
}
return fac;
}
int main() {
int x, i, input, res, y[100];
scanf("%d", &x);
if(1<=x<=100) {
for(i = 0; i < x; i++) {
scanf("%d", &input);
if(1<=input<=100) {
y[i] = input;
}
}
}
for(i = 0; i < x; i++) {
res = fact(y[i]);
printf("%dn", res);
}
return 0;
}

 

 

 

why this code showing wrong answer?

Please don't post code. Read

triplem @ 23 Feb 2010 04:20 AM

Please don't post code. Read the FAQ; it is giving wrong answer for a reason that would be very obvious if you had tested it properly.

can you please check what is

moizabdul18 @ 25 Feb 2010 07:20 PM

can you please check what is error in my code

check under my submissions

please post solution

its workin gfine in my dev c++

The problem says 1 <= n <=

triplem @ 26 Feb 2010 05:26 AM

The problem says 1 <= n <= 100.

Except you clearly haven't tried anything near 100. (And you are printing out the input again too, which you aren't meant to do).

i am receiving runtime

cool_rayat @ 27 Feb 2010 04:21 PM

i am receiving runtime error...

plz help me ...

import

ad11985@yahoo.co.in @ 1 Mar 2010 03:36 PM

import java.io.DataInputStream;


public class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

DataInputStream d = new DataInputStream(System.in);
int i,k = 0;
int j[];
long fact;
try{

i = Integer.parseInt(d.readLine());
j = new int[i];

while (i > 0){
j[k] = Integer.parseInt(d.readLine());
k++;
i--;
}
k--;
for (k=0;k<j.length;k++){
fact = j[k];
i = (int) fact;
while(i>1){
fact = fact*(i-1);
i-- ;
}
System.out.println(fact);
}
}
catch(Exception e){
e.printStackTrace();
}

}

}

 

// I am not sure what is wrong with this code, works perfectly fine on my system.

//someone help

No it doesn't. It very

triplem @ 1 Mar 2010 04:39 PM

No it doesn't. It very clearly fails on any large input.

I tried with t = 60, it was

ad11985@yahoo.co.in @ 1 Mar 2010 05:18 PM

I tried with t = 60, it was not giving me any runtime error.

For an input of 60 you print

triplem @ 2 Mar 2010 03:22 AM

For an input of 60 you print -8718968878589280256.. I'm not sure why you think 60! is going to be a negative number.

@ to all who say "I have

cranil @ 4 Mar 2010 06:44 PM

@ to all who say "I have checked for 100! and I got right answer!" wondering how you checked :P

My Java code for this

rajesh10408 @ 30 Mar 2010 03:10 PM

My Java code for this program is

 

import java.util.*;

import java.math.*;

 

class fctrl2

{

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

int k = in.nextInt();

for(int i=0;i<k;i++)

{

int n = in.nextInt();

BigInteger fact = BigInteger.valueOf(1);

for(int j=0;j<n;j++)

{

fact = fact.multiply(BigInteger.valueOf(n-j));

}

System.out.println(fact);

}

}

}

 

on submitting the solution, it is giving compile time error and the warning is

/sources/Main.java:4: class fctrl2 is public, should be declared in a file named fctrl2.java public class fctrl2 ^ 1 error

Can anyone explain what is this

Also my code is working fine

rajesh10408 @ 30 Mar 2010 03:11 PM

Also my code is working fine for 100!

FAQ

triplem @ 30 Mar 2010 03:54 PM

FAQ

codechef is not accepting a

parveenlukha @ 2 Apr 2010 11:01 AM

codechef is not accepting a php solution please check

i have followed all the guidelines

but its not accepting php code following is code it says wrong answer please help to sort out

thanks

<?php
$number=fgets(STDIN, 8);
for($i=0;$i<$number;$i++)
{
$in=fgets(STDIN, 8);
$fact[$i]=1;
for($j=1;$j<=$in;$j++)
$fact[$i]=$fact[$i]*$j;
}
for($i=0;$i<$number;$i++)
{
echo $fact[$i];
echo "n";
}
?>

what should be output in case

parveenlukha @ 2 Apr 2010 12:01 PM

what should be output in case of value higher than 100?

The problem statement clearly

triplem @ 2 Apr 2010 12:43 PM

The problem statement clearly states the value will be at most 100.

#include<iostream.h>#include<

santosh keswani @ 8 Apr 2010 02:28 AM

#include<iostream.h>
#include<conio.h>
void main()
{
int fact=1;
int i;
clrscr();
cout<<"enter any number"<<endl;
cin>>i;
while(i!=0)
{
fact=fact*i;
i--;
}
cout<<"factorial of given number="<<fact;
getch();
}

Hi, I got a RTE for my

umangd @ 29 Apr 2010 02:12 AM

Hi,

I got a RTE for my submission. I dont think I can paste the code here. Can someone check the code and hint me where I am using up too much memory. I have used an array of 200 as per the tutorial. Cant figure out any other place which could cause memory problems.

 

Thanks,

Umang

for this

bananas33 @ 6 May 2010 05:05 PM

for this input:

8
1
2
5
50
3
100
4
17

 

I write this output:

1
2
120
30414093201713378043612608166064768844377641568960512000000000000
6
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
24
355687428096000

 

and I cannot see why I'm getting 'wrong answer' - these values and others I've tried seem right, the output format seems right but clearly I'm missing something, can anyone help?

oops, something seems to have

bananas33 @ 6 May 2010 05:06 PM

oops, something seems to have eaten the end of the 100! result, 64000000000000000000000000 is missing

can u help me in telling how

ni8mare @ 8 May 2010 08:36 PM

can u help me in telling how to improve my efficiency as my code is correct but still it is not upto the mark as other's have submitted and their execution time is less and memory is also less .

How to handle large numbers

harshvardhanflare @ 16 May 2010 05:00 PM

How to handle large numbers which are out of capacity of "long" datatype in "C"....??

The same way you would handle

triplem @ 17 May 2010 07:03 AM

The same way you would handle them on paper.

Rite....we may handle a

harshvardhanflare @ 17 May 2010 05:28 PM

Rite....we may handle a number containing 1000 digits, on paper, but no datatype in C can make that. We can handle an integer of any length by long datatype in python. I want to know if we make the same there in C by using any data structures.

@Harsh use char array for big

devendra088 @ 17 May 2010 07:27 PM

@Harsh

use char array for big integer in C

in the folllowing python

harshvardhanflare @ 18 May 2010 01:25 AM

in the folllowing python code

t = input()
p=1
if(int(t)>=1):
if(int(t)<=100):
for i in range(int(t)):
n = input()
if(int(n)>=1):
if(int(n)<=100):
j = int(n)
if(j>=1):
p*=j
j-=1
print(p)

please suggest the indentation wise position of last print statement, highlighted in bold.

does java takes more time

shuaib.akram @ 18 May 2010 03:10 PM

does java takes more time than c and c++??

i have done the problem... but time limit exceeded...

none of the successful subbmissions were in java...

heres the code..

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Life {
public static void main(String[] args) throws NumberFormatException, IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
while(n-->0){
int k=Integer.parseInt(br.readLine());
String res="1";
for(int i=2;i<=k;i++){
res=multip(res,""+i);
while(res.startsWith("0")){
res=res.substring(1);
}
}
System.out.println(res);
}
}   

private static String multip(String s1, String s2) {
String[] re=new String[s1.length()];
for(int i=s1.length()-1;i>-1;i--){
int rem=0;
re[i]="";
for(int j=i+1;j<s1.length();j++)
re[i]="0"+re[i];
for(int j=s2.length()-1;j>-1;j--){
int a=Integer.parseInt(""+s1.charAt(i));
int b=Integer.parseInt(""+s2.charAt(j));
re[i]=((a*b+rem)%10)+re[i];
rem=(a*b+rem)/10;               
}
re[i]=rem+re[i];
for(int j=0;j<i;j++)
re[i]="0"+re[i];
}
String res="";
int rem=0;
for(int j=re[0].length()-1;j>-1;j--){
for(int i=0;i<re.length;i++){
rem+=Integer.parseInt(""+re[i].charAt(j));
}
res=(rem%10)+res;
rem/=10;
}
return res;
}
}

You will find Haskell

janeve_george @ 24 May 2010 02:13 PM

You will find Haskell solution to this problem @ http://www.janeve.me/articles/learning-haskell/small-factorials-solution-in-haskell with a brief explanation of how the code works.

 

 

 

 

 

 

#include<stdio.h>#include<con

Neeraj1990 @ 28 May 2010 10:14 PM

#include<stdio.h>
#include<conio.h>
#include<math.h>

int main()
{
int i,j=1,t,temp,x,n,m[100],n1[100][150]={0},qq,ii;

scanf("%d",&t);
for(qq=0;qq<t;qq++)
{
scanf("%d",&n);
n1[qq][0]=1;
for(i=2;i<=n;i++)
{
m[qq]=0,temp=1;

while(1)
{

if(m[qq]==0)
temp=0;
if(m[qq]>=j)
{
if(temp==0)
break;
n1[qq][m[qq]++]=(temp%10);
temp/=10;++j;

}
if(m[qq]<j)
{
x=n1[qq][m[qq]]*i+temp;
n1[qq][m[qq]]=x%10;temp=x/10;
m[qq]++;

}

}
}


}
for(qq=0;qq<t;qq++)
{
for(ii=m[qq]-1;ii>=0;ii--)
printf("%d",n1[qq][ii]);
printf("n");
}
//tch();
return 0;
}
pls help me

hear i did not find any

sivaji konapala @ 13 Jul 2010 09:27 AM

hear i did not find any runtime errors but after submition it shows a runtiome error.

how know it?

Have a look at the FAQ (in

triplem @ 13 Jul 2010 10:41 AM

Have a look at the FAQ (in particular, the first section and the section called 'Why do I get an NZEC?').

The following program is

AnoopNarang @ 14 Jul 2010 12:26 AM

The following program is working perfect and got ac , I wanna know how fact variable is able to store 100!

 

t=input()
l=[]
def fac(n):
fact=1
for i in xrange(1,n+1):
fact=fact*i
return fact
for i in xrange(1,t+1):
j=input()   
l.append(fac(j))
print('n')
for i in l:
print i

err , there are no spaces in

AnoopNarang @ 14 Jul 2010 12:28 AM

err , there are no spaces in program ...... view the program here. http://pastebin.com/PN8ZR1EN

can anybody tell me what's

credo @ 2 Aug 2010 11:35 AM

can anybody tell me what's wrong with this? I'm getting the right output in my gcc compiler!

thanx...

#include<stdio.h>
int main(){
int i,j,k;
unsigned int a[200],num,m,mul,temp=0,x,inputs;
scanf("%d",&inputs);/*number of test cases.*/
for(i=0;i<inputs;i++){
scanf("%d",&num);
temp=num;
m=0;
while(temp>0){
a[m]=temp%10;
temp/=10;
m++;
}
temp=0;
for(j=num;j>0;j--){
mul=j-1;
for(k=0;k<m;k++){
x=a[k]*mul+temp;
a[k]=x%10;
temp=x/10;
}
while(temp>0){
a[m]=temp%10;
m++;
temp/=10;
}
}
for(j=m;j>=0;j--){
printf("%d",a[j]);
}
}
return 0;
}

fact = input()result = 1for i

ShubhamJain @ 19 Aug 2010 08:56 AM

fact = input()
result = 1
for i in range(1, fact+1):
result *= i
print result

What wrong in above python solution. On my machine, it even returns the correct solution for 100.

93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

Read the input format, and

triplem @ 19 Aug 2010 10:36 AM

Read the input format, and make sure your program works on the sample input.

#include<iostream.h> #includ

kavibharathi @ 24 Aug 2010 12:53 AM

#include<iostream.h>

#include<conio.h>

void main()

{

 int n,x,z=1;

 clrscr();

 do

 {

 cout<<"Enter any no:";

 cin>>n;

 if(n<0 || n>100)

 {

 cout<<"Enter between the number 0 to 100 only.";

 }

 for(x=1;x<=n;x++)

 {

  z=x*z;

 }

 cout<<"nThe factorial of "<<n<<" number is:"<<z;

 }while(n<0 && n>100);

 getch();

}

@kavibharathi Read the input

javadecoder @ 24 Aug 2010 12:59 AM

@kavibharathi

Read the input constraints.

//#include<conio.h> #include

rohitdce.ec @ 26 Aug 2010 11:02 PM

//#include<conio.h>

#include<stdio.h>

#include<iostream>

using namespace std;

 

 

int main()

{

int test,i,j,k,l,m,n,arr[160],temp,fact;

scanf("%d",&test);

while(test--)

{

scanf("%d",&n);

arr[0]=n;

for(i=1;;i++)

{

if(arr[0]!=0)

{

arr[i]=arr[0]%10;

arr[0]=arr[0]/10;

}

else

break;

}

for(j=n-1;j>1;j--)

{

temp=0;

for(k=1;k<i;k++)

{

m=arr[k];

arr[k]=(m*j+temp)%10;

temp=(m*j+temp)/10;

}

for(l=i;;l++)

{

if(temp!=0)

{

arr[l]=temp%10;

temp=temp/10;

}

else

break;

}

i=l;

}

for(j=i-1;j>0;j--)

printf("%d",arr[j]);

}

//getch();

return 0;

}

please tell me whats wrong with it.I have checked the answer for almost every input and  it is coming right,but here they are showing wrong answer,please help!!!

Buddy ! where are the

ritesh104 @ 29 Aug 2010 09:46 PM

Buddy ! where are the newlines ?

My php code is below. It says

webspiral @ 1 Sep 2010 03:01 PM

My php code is below. It says time limit exceeded. I have tested it. It works fine even with larger values. Still it says time limit exceeded. Can someone point me what i am doing wrong ?

<?php
$file = fopen($argv[1], "r");
$num_of_lines_in_file = 0;
while(!feof($file))
{
$records = fgets($file);
//$records = trim($lines);
if($num_of_lines_in_file == 0)
{
$totalrecords = $records;
}
else
{           
echo nfact($records);
echo "n";
}
$num_of_lines_in_file++;       
}
fclose($file);


function nfact($n)
{
if ($n == 0)
{
return 1;
}
else
{
return $n * nfact($n - 1);
}
}


?>

You need to read input from

triplem @ 1 Sep 2010 04:50 PM

You need to read input from stdin. See the FAQ.

this is the only problem i

devanshukashyap @ 6 Sep 2010 02:20 AM

this is the only problem i was able to solve here. It judges you how u r able to manage the time space tradeoff.

1)create a class defining big numbers as explained in the tutorial and overload the multiplication operation in ur class.

2)Create an object array of 101 elements (0 to 100).

Suppose user enters 44 as input. starting frm 0 fill the array corresponding to the index as u calculate the factorial, so that next time if user enters value less than 44, its factorial could be easily obtained frm the array by indexing it , because to find 44! we have already stored the intermediate calculations. if user happens to enter value more than 44 say 70 later, then continue the halted loop from 44 to 90, and save the factorials falling within this range too as u proceed.

thus the loop would run only once and data can be accessed any number of times. This was the time space tradeoff.

O god,, help me with other

devanshukashyap @ 6 Sep 2010 02:22 AM

O god,, help me with other probs...

Its very difficult to to get the striking thought.

Can anyone plzz help me gaining skills??

plzz....

in my case the problem is

dataq @ 9 Sep 2010 04:05 PM

in my case the problem is caused by 100!

In Java the variable long is not large enough to store the answer. So we have to use java.math.BigInteger

http://www.codechef.com/wiki/faq#How_can_I_store_very_very_large_integers_accurately

maybe this link can help you

http://leepoint.net/notes-java/data/numbers/10biginteger.html

I ve submitted my code in

sakshi215 @ 13 Sep 2010 02:36 PM

I ve submitted my code in java using BigDecimal class

and it is working fine on my machine

bt i m getting compilation error while submitting here.

Can anyone help me in this case.

I have the strong feeling

sapiens @ 20 Sep 2010 06:01 PM

I have the strong feeling that the "wrong answers" being shown against my submissions for this and other problems are due to an over-strict infexible output format demanded, e.g. whether the newline is before the data or after the data. People lose enthusiasm if such trivialities are held so sacrosanct.

Your strong feeling is

triplem @ 21 Sep 2010 06:53 AM

Your strong feeling is incorrect. Any extra whitespace in your output is ignored; you could print 20 tabs between each answer and no newlines if you preferred and still be judged correct. However, if an input file was, say

3

1

1

1

and your output was 111, then that would clearly be a wrong answer.

I ve submitted my code in

sakshi215 @ 21 Sep 2010 09:57 AM

I ve submitted my code in java using BigDecimal class

and it is working fine on my machine

bt i m getting compilation error while submitting here.

Can anyone help me in this case.

Admin plzz reply.....

I honestly have no idea.

triplem @ 21 Sep 2010 11:12 AM

I honestly have no idea. Resubmitting exactly the same code that you got compile error for was accepted for me. Must have been some sort of glitch in the system.

What is wrong in this

agupta @ 14 Oct 2010 03:37 PM

What is wrong in this code

#include <stdio.h>
#define MAX 1000
void fact(int k)
{
register int i ; // register variable for fast access
int n[MAX],rem=0,total,count;
for(i=0;i<MAX;i++)
n[i]=0;
n[MAX-1]=1;
if ( k < 2 )
printf("1");
else
{
for(count=2;count<=k;count++)
{ i=MAX-1;
while(i>0)
{ total=n[i]*count+rem;
rem=0;
if(total>9)
{  n[i]=total%10;
rem=total/10;
}
else
n[i]=total;
i--;
}
rem=0;
total=0;
}
while(n[i]==0)
i++;
for(;i<MAX;i++)      //print of final arry.
printf("%d",n[i]);

}                                                 

}

int main()
{
int n,i,item;
int input[100];
scanf("%d ", &n);
for (i=0 ; i < n ; i++ )
{
scanf("%d/n",&input[i] );
}
for( i=0 ; i< n ; i++ )
{
fact(input[i]); 
printf("n");
}
return 0;
}

#include <stdio.h> long long

nvsubbarao @ 14 Oct 2010 05:48 PM
#include <stdio.h>
long long int fact(int n)
{
	if(n==0)
		return 1;
	return n*fact(n-1);
}

int main()
{
	int t,a;
	scanf("%d",&t);
	while(t>0)
	{
		scanf("%d",&a);
		printf("%lldn",fact(a));
		t--;
	}
	return 0;
}


whats wrong with this solution???

It gives the wrong answer for

triplem @ 15 Oct 2010 04:40 AM

It gives the wrong answer for nearly every input. Have you not tried any large ones at all?

WTH

bharadwaj_ksb @ 16 Oct 2010 05:58 PM

WTH

can anybody tell why it is

gargdeendayal03 @ 20 Oct 2010 03:49 PM

can anybody tell why it is giving wrong answer.........please

 

 

#include<stdio.h>
int fact(int n)
{
int f=1;
while(n)
{
f=f*n;
n--;
}
return f;
}
int main()
{
int t,n,i;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%d",&n);
printf("%dn",fact(n));
}
return 0;
}

See my comment two above

triplem @ 21 Oct 2010 01:54 AM

See my comment two above yours.

can any1 plz tel me how can i

priyac @ 25 Oct 2010 10:27 PM

can any1 plz tel me how can i get the real solution of tthis question

can any1 tel me how can i get

priyac @ 25 Oct 2010 10:28 PM

can any1 tel me how can i get the solution of the prob??????

?

can any one check the

sivach @ 29 Nov 2010 12:06 PM

can any one check the following...

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

i didnt understand why its wrong.....

Have you tried checking your

triplem @ 29 Nov 2010 02:33 PM

Have you tried checking your solution for 100? It won't be anything like what you print, since doubles aren't accurate enough to store that many digits. (In fact, it starts giving wrong answers even for much smaller inputs).

@Merriman: I checked my

sivach @ 29 Nov 2010 05:18 PM

@Merriman: I checked my values. But i am displaying my results for larger values in exponential format which are same as that of values produced in MScalculator. Is this an error?

Yes. You must produce every

triplem @ 30 Nov 2010 01:28 AM

Yes. You must produce every single digit.

#include<iostream> using

aishrajdahal @ 4 Dec 2010 08:56 PM

#include<iostream>

using namespace std;

class BigInt

{

private:

int m;

int a[100];

void parstoarr(int inp)

{

int i=0;

while(inp!=0)

{

int r=inp%10;

inp=inp/10;

a[i++]=r;

m++;

}

m--;

}

public:

BigInt()

{

m=1;

a[0]=1;

}

void multp(int p)

{

int x,temp=0;

int i=0;

for(;i<m;i++)

{

x=(a[i]*p)+temp;

a[i]=x%10;

temp=x/10;

}

if(temp>0)

{

while(temp!=0)

{

a[i++]=(temp%10);

temp=temp/10;

m++;

}

}

}

void shownum()

{

for(int i=m-1;i>=0;i--)

{

cout<<a[i];

}

cout<<endl;

}

void fctrl(int c)

{

for(int j=1;j<=c;j++)

{

this->multp(j);

}

}

};

int main()

{

int b[100];

int a;

 

cin>>a;

for(int j=0;j<a;j++)

{

cin>>b[j];

}

 

for(int j=0;j<a;j++)

{

BigInt i;

i.fctrl(b[j]);

i.shownum();

}

return 0;

}

 

Please help, its telling that the result is wrong although as per the test cases I used its correct.

 

 

 

 

var     t:integer;    

opelhoward @ 12 Dec 2010 10:09 PM
var
    t:integer;
    n:array [1..100] of integer;
    nf:array [1..10000,1..20000] of int64;
    l:array [1..10000] of integer;
    a,z:integer;
    max:integer;
procedure f(i:integer);
var x,y:integer;
    o:int64;
begin
    for y:=2 to i do
    begin
        o:=0;
        for x:=1 to l[y-1] do
        begin
            nf[y,x]:=((nf[y-1,x]*y)+o);
            o:=0;
            if nf[y,x]>9 then
            begin
                o:=nf[y,x] div 10;
                nf[y,x]:=nf[y,x] mod 10;
            end;
        end;
        x:=l[y-1];
        while o<>0 do
        begin
            x:=x+1;
            nf[y,x]:=o mod 10;
            o:=o div 10;
        end;
        l[y]:=x;
    end;
end;

begin
    nf[1,1]:=1;
    l[1]:=1;
    readln(t); max:=0;
    for z:=1 to t do
    begin
        readln(n[z]);
        if max<n[z] then
            max:=n[z];
    end;
    f(max);
    for z:=1 to t do
    begin
        for a:=l[n[z]] downto 1 do
            write(nf[n[z],a]);
        writeln;
    end;
end.

i run it in 0.00 sec Lang: PAS =)

Whats wrong with my

sabyasachi3 @ 14 Dec 2010 11:18 PM

Whats wrong with my code???

It is finely working in my machine...

 

#include<stdio.h>
#include<stdlib.h>

main()
{
int count, *num, f,i ;

printf("nEnter no. of numbers:t");
scanf("%d",&count);

num = ( int *)malloc( count*sizeof(int ));

for( i=0; i<count; i++ )
{   
scanf("%d",(num+i));

}



for(i=0;i<count;i++)
{
printf("%dn", fact( *(num+i) ))    ;
}


}

int fact( int num )
{
int i,result=1;

for( i=1; i<= num; i++ )
result = result*i ;

return( result );

}

 

 

Hi can anyone check this

shubham731 @ 15 Dec 2010 08:03 PM

Hi can anyone check this solution http://www.codechef.com/submit/complete/46523-24--4d08d0bb8ac15 it is giving wrong answer again and again. I have checked my solution for all no.s 1-100 and all of them are correct. My code if giving the exact output as other accepted solution output for numerous test cases. Please help me on this

Your last two submissions are

triplem @ 16 Dec 2010 02:29 AM

Your last two submissions are clearly wrong since they don't even work on the sample input. As for some of the submissions I checked before that; you said you tested 1-100, but have you tested 100-1?

To Admin: Please give some

rajneesh2k10 @ 17 Dec 2010 08:07 PM

To Admin: Please give some bigger test cases as I am not able to figure out whether the result I am getting is right or wrong!

My solution is evaluated as "Wrong Answer". If possible please check the issue.

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

If you're using windows you

triplem @ 18 Dec 2010 04:01 AM

If you're using windows you could always use windows calculator (similar options for linux)..

Got the issue! Logical

rajneesh2k10 @ 18 Dec 2010 09:21 AM
Got the issue! Logical mistake in program. Thanx anyway!!

@ Stephen Merriman Hi

cooltodinesh @ 24 Dec 2010 04:18 AM

@ Stephen Merriman

Hi Stephen, Please help into this.

I solved problems with all inputs and i got answer too.

Below is my file. Please have a look. I am getting 'wrong answer' error.

I checked all extra character but all program is correct....

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

hey plz somebody help me here

eagleye @ 2 Jan 2011 11:32 PM

hey plz somebody help me

here it is my code

#include<stdio.h>

int a[200],count=0,c=0;

void make_arr(int n)

{

int b=0,i=0;

do

{

b=n%10;

a[i]=b;

i++;

n=n/10;

count++;

}while((n/10)!=n);

}

 

void counti(int m)

{

do

{

m=m/10;

c++;

}while((m/10)!=m);

}

 

void countfact(int m)

{

int x;

static int j,temp;

x=m*a[j]+temp;

a[j]=x%10;

temp=x/10;

j++;

}

 

int main()

{

int n,i,b,j,m=0,l=0;

printf("enter no ");

scanf("%d",&n);

make_arr(n);

m=n;

for(i=n;i>0;i--)

{

m--;

counti(m);

l=count+c;

for(j=l;j>0;j--)

{

countfact(m);

}

}

/* for(j=0;j<9;j++)

{

printf("%d",a[j]);

} */

return 0;

}

 

can anyone tell me why my loop is not running second tym???

it gives the result only

eagleye @ 2 Jan 2011 11:36 PM
it gives the result only first time after multiply like for factorial 12 it gives 132 nd nt runnin second tym

admin plz help me

eagleye @ 3 Jan 2011 11:47 AM

admin plz help me

PLZZZZZZZZZZZ HELP ME.....Iam

timemind000 @ 4 Jan 2011 07:45 PM

PLZZZZZZZZZZZ HELP ME.....Iam geting Run time error....

This is my code.........................

 

 

#include<stdio.h>

#include<string.h>

int main()

{

short int i,j=0;

unsigned short int k=0,l=0,len1=0,len2=0,y=0,carry=0,x=0;

short int t[100],m=0,n=0,input=0;

char res[2][210]={"1","2"};

char one[210],two[4];

scanf("%d",&n);

if(n>100) exit(1);

for(i=0;i<n;i++)

{

scanf("%d",&t[i]);

if(t[i]>100) exit(1);

}

for(m=0;m<n;m++)

{

input=t[m];

one[2]=(char)(((input%10)+48));

input/=10;

one[1]=(char)(((input%10)+48));

input/=10;

one[0]=(char)(((input%10)+48));

one[3]='';

input=t[m];

if(input>2)

{

while(input!=1)

{

two[1]=(char)(((input-1)%10)+48);

two[0]=(char)(((input-1)/10)+48);

two[2]='';

len1=0;

len1=strlen(one);

for(i=1,k=0,l=0;i>=0;i--)

{

carry=0;

for(j=len1-1;j>=0;j--)

{

x=(one[j]-48)*(two[i]-48)+carry;

y=x%10;

carry=x/10;

res[k][l++]=(char)(y+48);

}

res[k][l]='';

l=0;

res[++k][l++]='0';

}

len1=0;

len2=0;

len1=strlen(res[0]);

len2=strlen(res[1]);

for(i=0;i<(len2-len1);i++)

{

res[0][len1++]='0';

}

res[0][len1]='';

carry=0;

for(i=0,k=0;i<len1;i++)

{

x=(res[0][i]-48)+(res[1][i]-48)+carry;

res[1][k++]=(char)((x%10)+48);

carry=x/10;

}

res[1][k++]=(char)(carry+48);

res[1][k]='';

len1=0;

len1=strlen(res[1]);

for(i=0;i<len1;i++)

{

one[i]=res[1][(len1-1)-i];

}

one[i]='';

input--;

}

i=0;

j=0;

k=0;

while(one[i]!='')

{

if(one[i]=='0'&&k==0)

{

i++;

continue;

}

else

k=1;

res[0][j++]=one[i++];

}

res[0][j]='';

printf("%sn",res[0]);

}

else

{

printf("%sn",res[input-1]);

}

}

return 0;

}

hello ppl plz help me out!!!!

timemind000 @ 5 Jan 2011 10:18 AM

hello ppl plz help me out!!!! Above is my code....

#include<stdio.h> long double

triptisamal @ 14 Jan 2011 08:03 PM

#include<stdio.h>

long double func(long double);

void main()

{

long double p;

long double a[200],t,x;

int i,j=0;

scanf("%Lf",&p);

for(i=0;i<p;i++)

{

scanf("%Lf",&t);

x=func(t);

a[j]=x;

j++;

}

printf("n");

for(i=0;i<p;i++)

printf("%Lfn",a[i]);

}

 

long double func(long double n)

{if(n==0)

return 1;

return (n*func(n-1));

}

on my computer it's showing correct answer, but here run time error. why?

See the FAQ.

triplem @ 15 Jan 2011 02:05 AM

See the FAQ.

Hey I have used C++.There is

puneet_50 @ 26 Jan 2011 07:52 PM

Hey I have used C++.There is no limit(maximum) to find the factorial of a number.I am getting correct answers on my PC but i am getting wrong answer every time on your machine.Can you please tell me what is wrong or any input whose my program gives wrong answer ?Here is my code..

#include<iostream>
#include<stdio.h>
#include<list>
using namespace std;
int main()
{
int tests = 1;
scanf("%d",&tests);
while(tests--)
{
int num = 1;
scanf("%d",&num);
if(num == 2)
{
printf("2");
continue;
}
else if(num <= 1)
{
printf("1");
continue;
}
int temp = num<<1;
list<int> vt;
while( temp > 0)
{
vt.push_front(temp%10);
temp /= 10;
}
int multiplier = 2;

while(++multiplier < num)
{
list<int>::iterator it = vt.end();
int carry_out = 0;
do
{
--it;
int temp1 = (*it) * multiplier; //  First multiply
temp1 += carry_out;             //  Then add carry out
carry_out = temp1/10;           //  Next carry out is divide by 10
*it = temp1 % 10 ;              //  This digit changes to ones place of the multiplication
}while(it != vt.begin());

while(carry_out > 0)
{
vt.push_front(carry_out % 10);
carry_out /= 10;
}
}

list<int>::iterator it = vt.begin();
while(it != vt.end())
{
cout<<*it;
++it;
}
cout<<endl;
}
return 0;
}

#include<stdio.h>void main(){

allwin @ 27 Jan 2011 09:18 PM

#include<stdio.h>
void main()
{
int i,f,a[10],n,j;
puts("Enter the no of terms");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
f=1;
for(j=1;j<=a[i];j++)
f*=j;
printf("%dn",f);
}
}

hey... if mine input

luvlyangel @ 31 Jan 2011 08:31 PM

hey... if mine input is:

 

5

1

3

123

4

5

 

then what should be the output and shoud it accept no. after 123.....

 

plz tel me.....

The problem tells you all

triplem @ 1 Feb 2011 06:15 AM

The problem tells you all numbers in the input will be at most 100..

I used "double" for

neha22 @ 2 Mar 2011 10:45 AM

I used "double" for calculation of factorials and the 100! was also calculated. and the output I printed with the help of System.out.printf("%.0f",factorial) the output was correct but everytime i get Wrong Answer can anyone tell me why?

Are you sure? This is not

mkagenius @ 2 Mar 2011 12:51 PM

Are you sure?

This is not correct.. http://ideone.com/Ridzr

@Neha if you are using the

fluteofcoder @ 7 Mar 2011 12:52 AM

@Neha

if you are using the method given in the above tutorial then you need not to use

double..since range of ans for 100! ll be larger than that can be hold in double data type

and answer will always be integer

please check my program i am

asachin96 @ 29 Mar 2011 07:10 PM

please check my program i am getting runtime error

can u plz check my program nd

chinta @ 12 Apr 2011 04:13 PM

can u plz check my program nd temme wher i went wrong...i got runtym error..:(

nd wil i b able to submit solution one more tym..??

can u plz check my program n

jagrati @ 13 Apr 2011 10:21 PM

can u plz check my program n tell me what is wrong with this code???

#include<stdio.h> #include<co

master_coder @ 14 Apr 2011 11:26 AM

#include<stdio.h>

#include<conio.h>

int fact(int num)

{ int k=1,i;

if(num==1)

return(1);

else

{

for( i=1;i<=num;i++)

k=k*i;

}

return(k);}

void main()

{          int n,a[100],i,j;

clrscr();

scanf("%d",&n);

for(i=1;i<=n;i++)

{

scanf("%d",&j);

a[i]=fact(j);

}

for(i=1;i<=n;i++)

{

printf("%d",a[i]);

}

getch();

}

what to do with this????  

arbab @ 28 Apr 2011 01:43 PM

what to do with this????

 

using namespace std;#include

dj_me @ 4 May 2011 08:20 PM

using namespace std;

#include <iostream>

int main()
{
int t,i,j;
cin>>t;
long double k[t+1],a[t+1];
for (i=0;i<t;i++)
cin>>k[i];
for (i=0;i<t;i++)
a[i]=1.0;
for (i=0;i<t;i++)
{ if (k[i]==0)
a[i]==1;
else
for ( j=1;j<=k[i];j++)
{
a[i]=a[i]*j;
}
}
for (i=0;i<t;i++)
cout<<"n"<<a[i];
return 0;
}

 

I don't know why is this submission not getting accepted ... infact it's being called wrong ... can you please give me a testcase

what is runtime error...?? i

sravya @ 21 May 2011 10:19 AM
what is runtime error...?? i have used only 4 variables n i got runtime error...is 4 variables too much memory for this question?

I have submitted my code 3

vaibhav6980 @ 7 Jun 2011 09:00 AM
I have submitted my code 3 times but it always says wrong answer. But code execute correctly in my system. Please Clarify

I've submitted my code 10

flexicoder @ 8 Jun 2011 08:08 AM
I've submitted my code 10 times and am always getting runtime error-SIGSEGV..... But I ran it on my system(in DEV Cc++ and visual studio both) FOR ALL INPUTS(yes all from 0 to 100!) and it ran correctly............ Please tell me why its giving me runtime error in CodeChef

seems scanf is leading to

flexicoder @ 16 Jun 2011 09:08 PM
seems scanf is leading to runtime errors ..... I just replaced scanf with cin and it got accepted!

@flexicoder: You are

balajiganapath @ 17 Jun 2011 12:17 PM
@flexicoder: You are declaring t and n as unsigned short but the format specifier in scanf is "%d" which is for signed int. Try using "%uh"

can i use recursion

ankitgems @ 21 Jun 2011 01:12 AM
can i use recursion

What's wrong with this

gsatcoet @ 24 Jun 2011 09:18 PM
What's wrong with this code: import java.io.*; import java.util.*; class MyClass { public static void main(String args[]) throws IOException { int num=0; double fact=0; BufferedReader br = new BufferedReader(new )InputStreamReader(System.in)); num= Integer.parseInt(br.readLine()); fact= facto(num); System.out.println(fact); } static double facto(int n) { if (n==1) return n; else return (n * facto(n-1)); } }

@gsatcoet, are you sure your

tijoforyou @ 24 Jun 2011 10:46 PM
@gsatcoet, are you sure your pgm finds the factorials for all numbers given as input in a single run??

What is wrong with

gundeep @ 1 Jul 2011 12:28 AM
What is wrong with http://www.codechef.com/viewsolution/586174 it works fine on my pc

@gundeep: Try submitting in

imnewcoder @ 1 Jul 2011 01:17 AM
@gundeep: Try submitting in C++(gcc-4.3.2) :) :)

@imnewcoder It worked,

gundeep @ 1 Jul 2011 07:30 AM
@imnewcoder It worked, THANKS.

What is the difference

gundeep @ 1 Jul 2011 07:36 AM
What is the difference between the two btw

where did i go wrong

coder102 @ 3 Jul 2011 01:13 PM
where did i go wrong ? http://www.codechef.com/viewsolution/589540 it works in my pc...

you should read the I/O

kevinfrankly @ 3 Jul 2011 05:16 PM
you should read the I/O tutorial in this web , it's slightly different, like you mustn't use this code anymore => std::cout << "Enter your name : "

my code is working on dev

abhnvj @ 5 Jul 2011 08:37 PM
my code is working on dev c++ but here i'm getting a runtime error can someone tell me what is the problem here is my code #include int fac(int); main() { int t,n[t],i,j; scanf("%d",&t); for(i=0;i

I am getting Run time error.

tanka @ 1 Aug 2011 02:28 PM
I am getting Run time error. wht aspect of program should i think to modify??

hello i used "long fact " to

melvinjose100 @ 1 Aug 2011 06:04 PM
hello i used "long fact " to hold the result....in JAVA...bt it hold the value upto 20!......WHAT CAN I DO TO INCREASE THE SIZE OF "fact" ?????????????.

why there is a run time

saurabhzx @ 9 Aug 2011 12:20 AM
why there is a run time error #include int main(void) { int a[10],r[10]; int i,j,n; clrscr(); printf("enter the number of elements u want to enter n"); scanf("%d",&n); printf("enter the elements n"); for(i=0;i

I created a input text file

yogeshdahiya @ 11 Aug 2011 04:17 AM
I created a input text file containing all 100 nos with the format as mentioned and redirected it to program as input and the result i am getting for all the cases are posted below. i think they r all correct. but my submission says its wrong. please check 1 2 6 24 120 720 5040 40320 362880 3628800 39916800 479001600 6227020800 87178291200 1307674368000 20922789888000 355687428096000 6402373705728000 121645100408832000 2432902008176640000 51090942171709440000 1124000727777607680000 25852016738884976640000 620448401733239439360000 15511210043330985984000000 403291461126605635584000000 10888869450418352160768000000 304888344611713860501504000000 8841761993739701954543616000000 265252859812191058636308480000000 8222838654177922817725562880000000 263130836933693530167218012160000000 8683317618811886495518194401280000000 295232799039604140847618609643520000000 10333147966386144929666651337523200000000 371993326789901217467999448150835200000000 13763753091226345046315979581580902400000000 523022617466601111760007224100074291200000000 20397882081197443358640281739902897356800000000 815915283247897734345611269596115894272000000000 33452526613163807108170062053440751665152000000000 1405006117752879898543142606244511569936384000000000 60415263063373835637355132068513997507264512000000000 2658271574788448768043625811014615890319638528000000000 119622220865480194561963161495657715064383733760000000000 5502622159812088949850305428800254892961651752960000000000 258623241511168180642964355153611979969197632389120000000000 12413915592536072670862289047373375038521486354677760000000000 608281864034267560872252163321295376887552831379210240000000000 30414093201713378043612608166064768844377641568960512000000000000 1551118753287382280224243016469303211063259720016986112000000000000 80658175170943878571660636856403766975289505440883277824000000000000 4274883284060025564298013753389399649690343788366813724672000000000000 230843697339241380472092742683027581083278564571807941132288000000000000 12696403353658275925965100847566516959580321051449436762275840000000000000 710998587804863451854045647463724949736497978881168458687447040000000000000 40526919504877216755680601905432322134980384796226602145184481280000000000000 2350561331282878571829474910515074683828862318181142924420699914240000000000000 138683118545689835737939019720389406345902876772687432540821294940160000000000000 8320987112741390144276341183223364380754172606361245952449277696409600000000000000 507580213877224798800856812176625227226004528988036003099405939480985600000000000000 31469973260387937525653122354950764088012280797258232192163168247821107200000000000000 1982608315404440064116146708361898137544773690227268628106279599612729753600000000000000 126886932185884164103433389335161480802865516174545192198801894375214704230400000000000000 8247650592082470666723170306785496252186258551345437492922123134388955774976000000000000000 544344939077443064003729240247842752644293064388798874532860126869671081148416000000000000000 36471110918188685288249859096605464427167635314049524593701628500267962436943872000000000000000 2480035542436830599600990418569171581047399201355367672371710738018221445712183296000000000000000 171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000 11978571669969891796072783721689098736458938142546425857555362864628009582789845319680000000000000000 850478588567862317521167644239926010288584608120796235886430763388588680378079017697280000000000000000 61234458376886086861524070385274672740778091784697328983823014963978384987221689274204160000000000000000 4470115461512684340891257138125051110076800700282905015819080092370422104067183317016903680000000000000000 330788544151938641225953028221253782145683251820934971170611926835411235700971565459250872320000000000000000 24809140811395398091946477116594033660926243886570122837795894512655842677572867409443815424000000000000000000 1885494701666050254987932260861146558230394535379329335672487982961844043495537923117729972224000000000000000000 145183092028285869634070784086308284983740379224208358846781574688061991349156420080065207861248000000000000000000 11324281178206297831457521158732046228731749579488251990048962825668835325234200766245086213177344000000000000000000 894618213078297528685144171539831652069808216779571907213868063227837990693501860533361810841010176000000000000000000 71569457046263802294811533723186532165584657342365752577109445058227039255480148842668944867280814080000000000000000000 5797126020747367985879734231578109105412357244731625958745865049716390179693892056256184534249745940480000000000000000000 475364333701284174842138206989404946643813294067993328617160934076743994734899148613007131808479167119360000000000000000000 39455239697206586511897471180120610571436503407643446275224357528369751562996629334879591940103770870906880000000000000000000 3314240134565353266999387579130131288000666286242049487118846032383059131291716864129885722968716753156177920000000000000000000 281710411438055027694947944226061159480056634330574206405101912752560026159795933451040286452340924018275123200000000000000000000 24227095383672732381765523203441259715284870552429381750838764496720162249742450276789464634901319465571660595200000000000000000000 2107757298379527717213600518699389595229783738061356212322972511214654115727593174080683423236414793504734471782400000000000000000000 185482642257398439114796845645546284380220968949399346684421580986889562184028199319100141244804501828416633516851200000000000000000000 16507955160908461081216919262453619309839666236496541854913520707833171034378509739399912570787600662729080382999756800000000000000000000 1485715964481761497309522733620825737885569961284688766942216863704985393094065876545992131370884059645617234469978112000000000000000000000 135200152767840296255166568759495142147586866476906677791741734597153670771559994765685283954750449427751168336768008192000000000000000000000 12438414054641307255475324325873553077577991715875414356840239582938137710983519518443046123837041347353107486982656753664000000000000000000000 1156772507081641574759205162306240436214753229576413535186142281213246807121467315215203289516844845303838996289387078090752000000000000000000000 108736615665674308027365285256786601004186803580182872307497374434045199869417927630229109214583415458560865651202385340530688000000000000000000000 10329978488239059262599702099394727095397746340117372869212250571234293987594703124871765375385424468563282236864226607350415360000000000000000000000 991677934870949689209571401541893801158183648651267795444376054838492222809091499987689476037000748982075094738965754305639874560000000000000000000000 96192759682482119853328425949563698712343813919172976158104477319333745612481875498805879175589072651261284189679678167647067832320000000000000000000000 9426890448883247745626185743057242473809693764078951663494238777294707070023223798882976159207729119823605850588608460429412647567360000000000000000000000 933262154439441526816992388562667004907159682643816214685929638952175999932299156089414639761565182862536979208272237582511852109168640000000000000000000000 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

my code : #include int

yogeshdahiya @ 11 Aug 2011 04:28 AM
my code : #include int main() { int a[35],m; int ntest,inp,i,j,temp,l,check; scanf("%d",&ntest); for(l=1;l<=ntest;l++) { scanf("%d",&inp); a[0]=1; m=1; for(j=2;j<=inp;j++) { temp=0; for(i=0;i=0;i--) printf("%06d",a[i]); if(l!=ntest) printf("n"); } return 0; }

oops found the prob

yogeshdahiya @ 11 Aug 2011 04:35 AM
oops found the prob

import java.io.*; class

swastika21 @ 29 Aug 2011 12:33 AM
import java.io.*; class abc { public static void main(String[] args)throws IOException { BufferedReader k = new BufferedReader(new InputStreamReader(System.in)); int n,j,i,no,fac; n=Integer.parseInt(k.readLine()); if((1<=n)&&(n<=100)) { for(i=0;i

import java.io.*; class

swastika21 @ 29 Aug 2011 12:34 AM
import java.io.*; class abc { public static void main(String[] args)throws IOException { BufferedReader k = new BufferedReader(new InputStreamReader(System.in)); int n,j,i,no,fac; n=Integer.parseInt(k.readLine()); if((1<=n)&&(n<=100)) { for(i=0;i

why the codes i submit here

swastika21 @ 29 Aug 2011 12:35 AM
why the codes i submit here are displayed in dis manner????

plz sme1 reply....!

swastika21 @ 30 Aug 2011 05:56 PM
plz sme1 reply....!

why it is not

seriousblack @ 31 Aug 2011 12:14 AM
why it is not accepted #include main() { long int k,n,j,c; c=0; scanf("%ld %ld",&n,&j); while(n--) { scanf("%ld",&k); if(k%j==0) c++; } printf("n%ld",c); }

@ admin sir kindly help

swastika21 @ 31 Aug 2011 01:35 AM
@ admin sir kindly help me....

@swastika21: Do not post the

vijay91 @ 31 Aug 2011 11:37 AM
@swastika21: Do not post the code here and read the FAQs thoroughly.. http://www.codechef.com/wiki/faq#What_am_I_allowed_to_post_as_a_comment_...

i get NZEC. I am using

uzair @ 5 Sep 2011 12:49 AM
i get NZEC. I am using python. admin, please look into

My code : import

rpathak2 @ 6 Sep 2011 02:45 PM
My code : import java.util.*; import java.io.*; class fact { long val; fact link; fact() { val=1; link=null; } } public class Factorial { public static void main(String args[])throws Exception { DataInputStream x=new DataInputStream(System.in); long n=Integer.parseInt(x.readLine()); fact a=new fact(); fact b=a; long t,r; for(long i=1;i<=n;i++) { a=b; r=0; while(a!=null) { t=a.val*i+r; a.val=t%10; r=t/10; while(r>0&&a.link==null) { a.link=new fact(); a=a.link; a.val=r%10; r=r/10; } a=a.link; } } print(b); } static void print(fact a) { if(a.link!=null) print(a.link); System.out.print(a.val); } }

i don't know why it is giving

impulsive @ 10 Sep 2011 08:04 PM
i don't know why it is giving wrong answer every time my code is: import java.util.Scanner; class fct { int[] f(int n) { int a[]=new int[200]; for(int i=0;i<200;i++) { a[i]=-1; } a[0]=1; for(int i=n;i>0;i--) { int temp=0; int k; for(k=0;a[k]!=-1;k++) { int m=a[k]*i+temp; a[k]=m%10; temp=m/10; } while(temp!=0) { a[k]=temp%10; temp=temp/10; } } return a; } } class Cc { public static void main(String[] args) { Scanner s=new Scanner(System.in); int tc=s.nextInt(); for(int i=0;i100) continue; int c[]=new fct().f(num); int k; for(k=0;c[k]!=-1;k++) {} for(int j=k-1;j>=0;j--) { System.out.print(c[j]); } System.out.println(); } } }

please help

impulsive @ 10 Sep 2011 08:05 PM
please help

on my pc it is working fine

impulsive @ 10 Sep 2011 08:05 PM
on my pc it is working fine

The common problem is that

salvadorld @ 16 Sep 2011 02:34 PM
The common problem is that the language don't have a Integer type with 158 digits and the float types print the number in cientific notation and this wrong. One solution is multiply like done by hand.

I can't understand where the

rokon1cuet_51 @ 25 Sep 2011 05:32 PM
I can't understand where the error is?can anyone plz help me. http://www.codechef.com/viewsolution/673146

which type of integer integer

rokon1cuet_51 @ 25 Sep 2011 08:43 PM
which type of integer integer i have to declare in case of finding 100!?plz help me.i m using visual c++ compiler.

@rokon1cuet_51: Read the

vijay91 @ 26 Sep 2011 12:45 PM
@rokon1cuet_51: Read the tutorial provided for this problem below this line "All submissions for this problem are available." by clicking on the link "here". or this is the direct link: http://www.codechef.com/wiki/tutorial-small-factorials

What's wrong with

humbhenri @ 2 Oct 2011 02:19 AM
What's wrong with this? #!/usr/bin/perl use strict; use warnings; my $input = <>; my ($n) = $input =~ /(d*)/g; while (<>) { last if ( $n == 0 ); $n--; my ($num) = /(d*)/g; my $fact = 1; $fact *= $_ for ( 1 .. $num ); print "$factn"; }

Hi Admin, Can we have some

echandan @ 30 Oct 2011 05:01 PM
Hi Admin, Can we have some more information about why my code fails at runtime, it would help me dig deep and debug well. Just saying runtime error, wrong answer etc is not enough. plz suggest? I have done testing of the code from my end, everything seems to be OK. Plz help

#include int main() { int

p_sai_prasant @ 12 Nov 2011 07:32 PM
#include int main() { int n,i,a[100],j,fact=1; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&a[i]); } for(i=1;i<=n;i++) { j=1; while(j<=a[i]) { fact=fact*j; j++; } printf("%d",fact); fact=1; printf("n"); } return 0; } i wrote this code , it is saying wrong answer please help me!!!

The only error I get is an

divyamrastogi @ 27 Nov 2011 04:18 PM
The only error I get is an extra '1' is added in between when I calculate 100! Can somebody help me with this. It seems to be a small bug.

Ok.. I got it :D

divyamrastogi @ 27 Nov 2011 05:23 PM
Ok.. I got it :D

Got it. Thank you.

divyamrastogi @ 27 Nov 2011 05:24 PM
Got it. Thank you.

:= not a easy problem ,thanks

singhakshat @ 5 Dec 2011 10:51 PM
:= not a easy problem ,thanks to tutorial !!!

what's wrong with this code

s1b2_313 @ 14 Dec 2011 12:02 PM
what's wrong with this code written in java? please explain.. it runs fine on my pc and works for 100 and other inputs... i printed the output in plain text form without the exponential part... yet, it's giving wrong answer ... import java.text.NumberFormat; import java.util.Scanner; public class Main { public static void main(String []args) { Scanner input = new Scanner(System.in); int testCase; int number; double result; String refinedNumber; testCase= input.nextInt(); while(testCase>0) { number = input.nextInt(); result = factorial(number); NumberFormat f = NumberFormat.getInstance(); f.setGroupingUsed(false); refinedNumber = f.format(result); System.out.println(refinedNumber); testCase--; } } static double factorial (int number) { if(number == 1 || number == 0) return number; else return number * factorial(number-1); } }

i can not understand why my

farhad @ 19 Dec 2011 10:03 PM
i can not understand why my submission is shown as wrong answer.

this program is running

ne0_007 @ 20 Dec 2011 11:16 PM
this program is running perfectly on my pc but when i uploaded it says compilation error .i dont understand y?????????

my code is giving a run time

king_3105 @ 29 Dec 2011 10:57 PM
my code is giving a run time error..... can nebody help? #include int a[200], k; void digit(int); int main() { int t, n[100], i, temp, x, j, l, z; scanf("%d",&t);//accepting the number of test cases //accepting the test cases for(i=0;i0) {digit(temp);} } for(z=k-1;z>=0;z--) { printf("%d",a[z]); } printf("n"); } return; } void digit(int n) { while(n>0) { a[k++]=n%10; n/=10; } }

my code is giving wrong

isha_ijp @ 30 Dec 2011 01:15 AM
my code is giving wrong answer but when i run it in my computer it gives same values as given..... my code is #include int fact(int temp) { if(temp==0) return 1; if(temp==1) return 1; if(temp>1) return temp*fact(temp-1); } int main() { int n[100],t,i,temp,m; scanf("%d",&t); for(i=0;i

#include #include #include lo

dhusor @ 7 Jan 2012 09:02 PM
#include #include #include long int fact(int x) { if(x==1) return 1; long int result=x*fact(x-1); return result; } int main() { int n,a[200]; scanf("%d",&n); int i; for( i=0;i

my code #include int

dageramit @ 9 Jan 2012 04:20 PM
my code #include int main() { int num,i; scanf("n%d",&num); for(;(num>=1)&&(num<=100);) { scanf("n%d",&num); i=1; for(;(num>1);) { i*=num; num--; } printf("n%d",i); } return 0; } its working fine but ,but on submitting it saying TIME LIMIT EXceeded .... can sumone help....???

@dageramit your code is

crazycoder_sns @ 21 Jan 2012 08:36 PM
@dageramit your code is right but its not optimize code....a tutorial has been given for this problem which is very good to understand how to manage large number in array.....check out some solutionswhich have beeb solved by many users....:-) :-)

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com