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
    • All Contests
    • June Challenge 2013
    • May Cook-Off 2013
    • May Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Factorial

Factorial

Problem code: FCTRL

  • Submit
  • All Submissions

All submissions for this problem are available.


The most important part of a GSM network is so called
Base Transceiver Station (BTS). These transceivers form the
areas called cells (this term gave the name to the cellular phone)
and every phone connects to the BTS with the strongest signal (in
a little simplified view). Of course, BTSes need some attention and
technicians need to check their function periodically.



The technicians faced a very interesting problem recently. Given a set of
BTSes to visit, they needed to find the shortest path to visit all of the
given points and return back to the central company building. Programmers
have spent several months studying this problem but with no results. They
were unable to find the solution fast enough. After a long time, one of the
programmers found this problem in a conference article. Unfortunately, he
found that the problem is so called "Traveling Salesman Problem" and it is
very hard to solve. If we have N BTSes to be visited, we can visit them in
any order, giving us N! possibilities to examine. The function expressing
that number is called factorial and can be computed as a product

1.2.3.4....N. The number is very high even for a relatively small N.



The programmers understood they had no chance to solve the problem. But
because they have already received the research grant from the government,
they needed to continue with their studies and produce at least some
results. So they started to study behavior of the factorial function.



For example, they defined the function Z. For any positive integer N,
Z(N) is the number of zeros at the end of the decimal form of number
N!. They noticed that this function never decreases. If we have two numbers
N1<N2, then
Z(N1) <= Z(N2). It is because we can never "lose" any
trailing zero by multiplying by any positive number. We can only get new
and new zeros. The function Z is very interesting, so we need a computer
program that can determine its value efficiently.


Input


There is a single positive integer T on the first line of input (equal to about 100000). It stands
for the number of numbers to follow. Then there are T lines, each containing
exactly one positive integer number N,
1 <= N <= 1000000000.


Output


For every number N, output a single line containing the single non-negative
integer Z(N).

Example

Sample Input:

6
3
60
100
1024
23456
8735373

Sample Output:

0
14
24
253
5861
2183837



Author: admin
Date Added: 1-12-2008
Time Limit: 8 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

aravindk @ 11 Jun 2009 11:24 PM

I've given the above mentioned input and I am getting the output mentioned, but when I submit, it says 'Wrong Answer'

sanecode @ 14 Jun 2009 07:46 AM

@aravind kesiraju

check the output for N=5 in your program

rooparam @ 14 Jun 2009 07:18 PM

Note: plz rember the special case for N = 5^t

debidatta @ 28 Jun 2009 06:05 AM

I cant inderstand why my solution is showing a run time error in c lang , c and c99 language.... my compiler is a turboc 4.5 and da program runs perfectly well here... any suggestions?

mukul_alld @ 28 Jun 2009 05:48 PM

Is there any way by which we can know input for which output is incorrect .

i0exception @ 29 Jun 2009 07:24 PM

@all
Please take a look at the FAQ at http://blog.codechef.com/2009/06/29/frequently-asked-questions/

james_vinett @ 3 Jul 2009 03:16 AM

I've successfully submitted this in java, but since java is much slower than c i decided to submit it again in c . my algorithm is exactly the same. my local test answers are correct. yet i keep getting the wrong answer message. i've checked for an off by one error on the input, but that does not seem to be it. any suggestions?

as6485 @ 17 Jul 2009 04:38 PM

Why can't I see other's solution to this problem.... whereas I can view other's solutions for problems like Enormous input test?

admin 2 @ 17 Jul 2009 05:01 PM

some problems have public solutions, some don't, we will add a visual indicator on the problem listing page shortly to make it easier to identify...

as6485 @ 17 Jul 2009 05:51 PM

@admin : well thanks for the reply... but why is this so?

admin 2 @ 17 Jul 2009 05:55 PM

@ayan cause it wouldnt be fun if all the answers were available :)

preity2812 @ 25 Jul 2009 08:28 PM

when i run my code on my pc, it works fine but dunno why it shows a runtime error here. /i am sure there cannot be time limit exceeding or ny other problem. what else may be the reason??

nishanttotla @ 26 Jul 2009 01:35 AM

I submitted a solution in C , and it works perfectly on my computer...but I got wrong answer as a result. Any ideas?

admin 2 @ 26 Jul 2009 07:57 AM

@preity Please read the FAQ and the sample program for JAVA at www.codechef.com/help

admin 2 @ 26 Jul 2009 07:58 AM

@Nishant The test cases are consistent. If you are getting WA, you would have to recheck your algorithm or implementation :)

cucheshire @ 29 Jul 2009 07:31 AM

why are there 7 example inputs and only 6 outputs?

prunthaban @ 29 Jul 2009 02:08 PM

@Aaron Err.. The first one is actually number of test cases and not exactly an input in the sense you mean :-)

doncorleone @ 30 Jul 2009 04:31 AM

Can ne1 put up a tutorial fr dis 1!

f1singerzx34 @ 30 Jul 2009 12:46 PM

i submitted the solution is java but it says time limit exceeded
pls have a look into it and help

admin 2 @ 30 Jul 2009 06:34 PM

@D.Das There isn't much of coding involved in this one. Most of it is mathematical, so putting up a tutorial won't be of any help.
@Arbha What is the complexity of your solution ?

doshidevang @ 3 Aug 2009 07:47 AM

can ne1 explain wat is Z(N) in detail say N 4 wat will be z?

rediscoverjava @ 5 Aug 2009 07:28 PM

I need help with my solution. I tried every possible number and seem to be getting the right answer. Cant figure out why my solution is failing. I think its with the input output statements. I'm a little so any help would be appreciated
Thanks
Gimme Red

admin 2 @ 5 Aug 2009 07:36 PM

Z(n) is the number of zeroes at the end of N!. So if N=4, then Z(N) = 0.

@gimme red : The test data is consistent. The value of N can be pretty large.

nithinag @ 5 Aug 2009 11:11 PM

i am gettin the o/p as mentioned above. to make it sure that my prg is givin the right o/p tried for many other no's as well its givin out the right o/p...but the site isnt acceptin the prg. have submitted it 8 times. mods help!

nithinag @ 5 Aug 2009 11:19 PM

i got it to be submiteed...thanks anyways....

rediscoverjava @ 6 Aug 2009 02:05 AM

Dear Admin,
I getting 0 for Z(4). I'm getting answers for very large numbers like Z(456789000) =114197244. Not sure why its failing.
Gimme Red

admin 2 @ 6 Aug 2009 02:17 AM

This could be because your algorithm has a bug.

rediscoverjava @ 6 Aug 2009 05:03 AM

Dear Admin,
Unless you guys share the test data we wouldnt know where it is failing. The error could be IO related or something else. If you dont give us any hints or share the test data it will be hard to find out whats wrong
Here's some more test data
Z(1...4) = 0
Z(5...9) = 1
Z(100) = 24
z(1000)=249
z(100000000)= 24999999

admin 2 @ 6 Aug 2009 06:33 PM

I checked your solution, you are not having an IO related problem. You are definitely getting a wrong answer for one of our test cases.

leppyr64 @ 7 Aug 2009 05:03 AM

@gimme red - what's your answer for 1000000000?

rediscoverjava @ 7 Aug 2009 08:26 AM

I'm getting
Z(99999999999) = 249999989
Z(1000000000) = 249999998
I checked manually seems like the right answer

rediscoverjava @ 7 Aug 2009 12:19 PM

dear admin,
Could you please share the test data for which you think my program doesnt work.
GR

leppyr64 @ 7 Aug 2009 05:52 PM

@gimme red - pm your code to me on the forum (leppy) and I'll take a look for you.

admin 2 @ 7 Aug 2009 06:45 PM

At the moment it is not possible to share the test data. Your code seems to be failing for only one of the test cases.

sheikhaman @ 8 Aug 2009 02:25 PM

@Prunthaban

Thanks..i had same doubts about that!!

rediscoverjava @ 9 Aug 2009 06:40 AM

Dear Admin,
I think I found the test case its failing on. Z(0) = 0; I fixed it but its still failing
GR

triplem @ 9 Aug 2009 11:37 AM

The problem says N>=1, so that was never going to be in the input.

pranav2579 @ 9 Aug 2009 03:09 PM

the problem is not clear as the first 1....
we understand somthing else from the example and some other idea is given by the text......

admin 2 @ 9 Aug 2009 08:11 PM

What is not clear in the problem statement?

spike @ 10 Aug 2009 09:43 AM

@Gimmie Red: I actually find it quite amusing that you have figured out an algorithm that will solve all the test cases EXCEPT one. That's very interesting. I don't know how that's possible. Nice work. :-D

vikas_singla86 @ 17 Aug 2009 04:22 PM

I can't see others' solutions for this problem.

admin 2 @ 17 Aug 2009 04:24 PM

The solutions to this problem are not public as of now. So, you won't be able to see any of the solutions.

ivy1000 @ 17 Aug 2009 05:57 PM

#include<stdio.h>

void z(int n,long a[])
{
long res[50]={0};
int i;
for(i=0;i<n;i )
{
while(a[i]>=5)
{
a[i]=a[i]/5;
res[i]=res[i] a[i];
}
}

for(i=0;i<n;i )
printf("%ld\n",res[i]);
}

void main()
{
int n,i;
long a[50];
printf("enter sample input\n");
scanf("%d",

ivy1000 @ 17 Aug 2009 05:58 PM

i removed conio.h header from my prg, still it is giving runtime error . It is running successfully in turbo c.

admin 2 @ 17 Aug 2009 06:00 PM

You shouldn't print anything other than the required things. Don't print "Enter sample input"

admin 2 @ 17 Aug 2009 06:03 PM

Don't use turboC. It is an outdated program. Please read http://www.codechef.com/help/ and http://blog.codechef.com/2009/06/29/frequently-asked-questions/ for more information.

ivy1000 @ 17 Aug 2009 06:21 PM

The FAQ says that the conio header has to be removed. still, i am getting a runtime error

#include main() { long int

nitish_singla2 @ 18 Aug 2009 02:47 PM
#include main() { long int n,f=1; printf("nEnter the Number:"); scanf("%ld",&n); while(n>1) { f=f*n; --n; } printf("The factorial of a given number=%ld",f); }

respected sir i have an

nitish_singla2 @ 18 Aug 2009 02:51 PM
respected sir i have an message is replied from u that a "RUNTIME ERROR". Please solve my problem as soon as possible. with regards Nitish Singla user name:nitishsingla2

#include int main() {

shaileshbhat @ 19 Aug 2009 02:55 PM
#include int main() { return 0; }

i have an error like runtime

nitish_singla2 @ 21 Aug 2009 12:49 PM
i have an error like runtime error and in my pc there is no error in my program so why u tell that there is a RUNTIME ERROR plz..... try to solve my problem

The function main() should

admin @ 21 Aug 2009 01:21 PM

The function main() should always return an int and on successful termination should return a 0. You are missing the return 0; at the end of your code. Also, your function should be int main(void) and not main().

hey i know its not the place

nishantb @ 21 Aug 2009 04:34 PM
hey i know its not the place to ask but please... from where do i access the questions of august mini challenge..when i go to compete->august mini challenge ...unable to see any question

It says on the page itself..

triplem @ 21 Aug 2009 04:36 PM

It says on the page itself.. Contest problems will become visible on August 22nd 15:00 IST(05:30 EDT).

do i have to register

nishantb @ 21 Aug 2009 04:37 PM
do i have to register somewhere for the august mini challenge?

but on the home page its

nishantb @ 21 Aug 2009 04:43 PM
but on the home page its saying..it is in progres...

what does that actually mean

nishantb @ 21 Aug 2009 04:45 PM
what does that actually mean

The august mini challenge

admin @ 21 Aug 2009 04:57 PM

The august mini challenge will start tomorrow at 15:00 hrs IST. And this is not the place to ask these questions. If you have such queries, you can mail them to us at admin@codechef.com

@admin i hv submitted the

abhijeeet @ 22 Aug 2009 10:12 AM
@admin i hv submitted the soln in java and it says der is error while compiling. my code works perfectly fine for all the test cases... may i knw wat is lacking in my pgm ...

@admin : can we have some

abhijeeet @ 22 Aug 2009 10:31 AM
@admin : can we have some info on how long the input numbers be ... very large is kind of vague ... plss be precise

It tells you how large the

triplem @ 22 Aug 2009 10:35 AM

It tells you how large the input numbers are in the Input section.

See this thread for a sample solution in Java that compiles. You probably aren't calling the class Main or something like that.

oops .. my mistake

abhijeeet @ 22 Aug 2009 11:04 AM
oops .. my mistake

@admin :: can sum1 plss tell

abhijeeet @ 24 Aug 2009 09:05 PM
@admin :: can sum1 plss tell me wats wrong wid d java code i hv submitted??? the effort will be highly appreciated

hi everybody, I am have

kartikdadwal @ 26 Aug 2009 02:08 PM
hi everybody, I am have written the code in perl but there is one problem. When I enter a higher number ex. 60 and calculate its factorial, I get a number: 8.32098711274139e+81 I believe factorial is going out bounds. So now I cannot count number of zero's, as the factorial is in terms of 'e'. Can the admin or anybody else help on this..??

You won't be able to

triplem @ 26 Aug 2009 05:29 PM
You won't be able to calculate N! exactly in the time limit. You'll need to figure out a way of counting 0s without generating the number itself.

hi everybody, I am have

kartikdadwal @ 27 Aug 2009 03:55 PM
hi everybody, I am have written the code in perl but there is one problem. When I enter a higher number ex. 60 and calculate its factorial, I get a number: 8.32098711274139e+81 I believe factorial is going out bounds. So now I cannot count number of zero's, as the factorial is in terms of 'e'. Can the admin or anybody else help on this..?? @stephan : time limit is not a concern, but I am getting the result for big numbers like 30, 35 , etc in terms of 'e'. Thats the reason I cant see the number of zeros in factorial of those numbers.

You don't have to calculate

admin @ 27 Aug 2009 04:00 PM

You don't have to calculate the factorial of the number in order to find out the number of zeroes at the end.

#include<iostream> using

erahul.ag @ 29 Aug 2009 09:44 AM

#include<iostream>
using namespace std;
int main( int argc, char* argv[]){
    int c=0;
    cin>> c;
    while(c--){
        long long int num=0,r=0,pow=5;
        cin >> num;
        while(num/2 > pow){
            r+=num/pow;
            pow*=5;
        }
        cout << r<< endl;
    }
    return 0;
}

I want test data to see y my prog is not working....

:(

Hey zero1.. its good that your solutions clears the regressions.

Can you share it...

 

Have you tested your code at

triplem @ 29 Aug 2009 09:58 AM

Have you tested your code at all? Try the numbers 1-10, at least. Half of them give the wrong answer.


@Directi-Admin: according to

codemonk @ 29 Aug 2009 11:17 PM

@Directi-Admin: according to problem Z(N) returns the number of trailing zeroes for the decimal form of  N!. but in the examples given for an i/p of 6 output is given as 0  but we know that 6!=720...so the output should be 1.????  i am not able figure out howcome every1 else understood the problem...??

Please correct me if i m wrong...

6 is not one of the values

triplem @ 30 Aug 2009 03:46 AM

6 is not one of the values you should calculate an answer for. Read the 'input' section.

@Stephen : Oops!!! Thanks u

codemonk @ 30 Aug 2009 05:05 PM

@Stephen : Oops!!! Thanks u so much Stephen...was in a hurry to solve...so...may be i missed tht line.... anyways thanks a lot for pointing out...

Hi Stephen Thanks for your

erahul.ag @ 31 Aug 2009 09:36 AM

Hi Stephen

Thanks for your comment.

It was last minute change to optimize the code make it failure.

 

Rahul Agarwal

How could 6 isn't one of the

jshowa @ 1 Sep 2009 09:15 PM

How could 6 isn't one of the numbers to be calculated when 1 <= N <= 1000000000?

Never mind, I'm an idiot.

jshowa @ 1 Sep 2009 09:30 PM

Never mind, I'm an idiot.

what is maximunm that can be

gauravgupta @ 4 Sep 2009 09:53 AM

what is maximunm that can be given as input

It says that in the section

triplem @ 4 Sep 2009 10:09 AM

It says that in the section titled 'Input', surprisingly enough.

#include<stdio.h> int

ranjeet.mnnit @ 4 Sep 2009 11:59 PM

#include<stdio.h>
int main()
{
int n1,n,i,d,c;
scanf("%d",&n1);
for(i=0;i<n1;i++)
{
scanf("%d",&n);
c=n/5;d=c;
while(1)
{
        if(c==0) break;
        else d=d+(c=(c/5));
}
printf("%dn",d);
}
}
 

why this is givin runtime error  even though it is calculating all right answers..

 

suggest me some good mehod for doin this

thanks in advance........
 

You are missing a return 0;

admin @ 5 Sep 2009 02:28 PM

You are missing a return 0;

 HI, I'm getting an NZEC

boxer @ 6 Sep 2009 03:30 AM

 HI,

I'm getting an NZEC error for some reason. My code is in python (solution no. [88120]):

 

s=raw_input()
 
PowersOfFive= [5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 48828125, 244140625]
 
#s=raw_input()
t=int(s)
Out=[]
for x in range (0,t):
  m=raw_input()
  n=int(m)
  i=0
  while (n>PowersOfFive[i]):
  i=i+1
   
  Zeroes=0
  for j in range (0,i):
  Zeroes = Zeroes + n/PowersOfFive[j]
 
  Out.append(Zeroes)
 
for y in range(0,t):
  print Out[y]
 
 


Any clue as to what I'm doing wrong? 

plz explain i have submitted

abhikrmnnit @ 7 Sep 2009 01:35 AM

plz explain i have submitted the same code in c an c++ (including the little modification necessary)

But my code give compilation error in C++ but works fine in C .

@abhishek you need to take a

admin @ 7 Sep 2009 02:14 PM

@abhishek you need to take a look at www.codechef.com/help for a sample solution in c++. Check out the compilers we are using and make sure your code compiles fine on those.

#include<stdio.h> void

sasidharevuru @ 7 Sep 2009 07:47 PM

#include<stdio.h>

void main()

{

int i,n,f=1;

printf("enter the value of n");

scanf("%d",&n);

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

f=f*i;

printf(factorial is "%d",f); 

} 

can any one tell me wy this programme is wrong

  #include<stdio.h>long

saurabh_priya @ 10 Sep 2009 07:59 PM

 

  1. #include<stdio.h>
  2. long sm(int,long);
  3. int main()
  4. {int t,i;
  5. long x[10],s;
  6. scanf("%d",&t);
  7. for(i=0;i<t;i++)scanf("%ld",&x[i]);
  8. for(i=0;i<t;i++){s=sm(5,x[i]);printf("%ld",s);}
  9. return 0;}
  10. long sm(int a,long x)
  11. {long k=0,l=0,j;j=a;
  12. while(x>=j){
  13. l=x/j;k=k+l;j=j*a;}
  14. return k;}
    plzzzzz point out the mistake.......... its giving correct answer on my system........

 sorry for pasting the

saurabh_priya @ 10 Sep 2009 08:20 PM

 sorry for pasting the code..... m new here ..... but  this code gives correct answer on my system ..... i cnt figure out whts wrong ......

@Saurabh Your code prints all

ashishanand @ 10 Sep 2009 09:02 PM

@Saurabh Your code prints all the answers in the same line.There is a new line between the answers of different test cases

 i corrected that......but

saurabh_priya @ 10 Sep 2009 11:58 PM

 i corrected that......but still its not working ....... i am getting exact answer on my system ... with proper indentation but here its not accepting ...i even tried the unsigned data type..........

@Saurabh increase the size of

ashishanand @ 11 Sep 2009 02:35 AM

@Saurabh increase the size of the input array.There can be 100000 test cases and your array size is 10.

 dude i did tht .... i used

saurabh_priya @ 11 Sep 2009 12:30 PM

 dude i did tht .... i used long x[1000]...........but when it goes beyond 1000 it goes into run time error...... :-(

That is because 100000 longs

triplem @ 11 Sep 2009 12:43 PM

That is because 100000 longs is too big to fit on the stack. You could get around this by declaring it as static or moving it outside the main method, but you shouldn't have this array at all. Just read in each input, process it, and print out an output, just one long needed, not an array. If you try to store every single input in your program before doing any output you'll never be able to solve some problems here.

 thanx......

saurabh_priya @ 11 Sep 2009 01:39 PM

 thanx......

Hello every one! I dont

vineelyalamarthy @ 13 Sep 2009 01:51 AM
Hello every one! I dont understand why this code when submitted gets a fatal error. It compiled and ran on my PC.Please see the code and tell me what's wrong with it. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.*; /** * * @author vineel */ public class Vineel{ private static int fun( int sub) { int l=1; if(sub<5) return(0); else if(sub>=5) { while(sub>=l*5) { if(sub<(l+1)*5) return l; else l=l+1; } } return(l); } /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { // TODO code application logic here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int k =Integer.parseInt(br.readLine()); // System.out.println(k); { String str=null; int i=0; for(i=0;i=5) { while(sub>=l*5) { if(sub<(l+1)*5) return l; else l=l+1; } } return(l); } /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { // TODO code application logic here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int k =Integer.parseInt(br.readLine()); // System.out.println(k); { String str=null; int i=0; for(i=0;i

plz tell me what's wrong with

vineelyalamarthy @ 13 Sep 2009 01:55 AM
plz tell me what's wrong with this code. import java.io.*; public class Main{ private static int fun( int sub) { int l=1; if(sub<5) return(0); else if(sub>=5) { while(sub>=l*5) { if(sub<(l+1)*5) return l; else l=l+1; } } return(l); } /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { // TODO code application logic here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int k =Integer.parseInt(br.readLine()); // System.out.println(k); { String str=null; int i=0; for(i=0;i

why no one is responding to

vineelyalamarthy @ 13 Sep 2009 01:57 AM
why no one is responding to it? Please see the code in the above comment and tell me what 's wrong with it?It ran on my PC successfully.But I get a fatal error when submitted

Don't use the plain-text

admin @ 13 Sep 2009 07:54 PM

Don't use the plain-text editor. Your code appears horribly jumbled-up because of that and that could be one of the reasons why no one is responding :) 

  Can some one help me?

vineelyalamarthy @ 15 Sep 2009 02:19 PM

 

Can some one help me? Please!  My solution gets compiled and runs on my system but when its submitted ,a compiler error is thrown.

please see this code and tell me what's wrong with this.

 

public

 

class Codechef {private static int fun(int sub)int sum=0;int i=1;boolean flag=false;while(flag==false)if(Math.floor(sub/Math.pow(5, i))>=1){int) (sum+Math.floor(sub/Math.pow(5, i)));false;else true;return sum;public static void main(String[] args) throws NumberFormatException, java.io.IOException {new java.util.ArrayList<Integer>();new java.io.BufferedReader(new java.io.InputStreamReader(System.in));int k=Integer.parseInt(br.readLine());for(int i=0;i<k;i++)int j = Integer.parseInt(br.readLine());while(itr.hasNext())int hudda= Integer.parseInt(itr.next().toString().trim());out.println(fun(hudda));

 

{

 

 

 

{

 

sum= (

i=i+1;

flag=

}

 

flag=

}

 

 

 

}

 

 

 

java.util.List<Integer> input =

java.io.BufferedReader br =

 

 

{

 

input.add(j);

 

}

java.util.Iterator<Integer> itr = input.iterator();

 

{

 

System.

 

}

 

 

}

 

}

Can some one help me?It does

vineelyalamarthy @ 15 Sep 2009 02:21 PM

Can some one help me?It does not get compiled!Its running on my system.

 

public

 

class Codechef {private static int fun(int sub)int sum=0;int i=1;boolean flag=false;while(flag==false)if(Math.floor(sub/Math.pow(5, i))>=1){int) (sum+Math.floor(sub/Math.pow(5, i)));false;else true;return sum;public static void main(String[] args) throws NumberFormatException, java.io.IOException {new java.util.ArrayList<Integer>();new java.io.BufferedReader(new java.io.InputStreamReader(System.in));int k=Integer.parseInt(br.readLine());for(int i=0;i<k;i++)int j = Integer.parseInt(br.readLine());while(itr.hasNext())int hudda= Integer.parseInt(itr.next().toString().trim());out.println(fun(hudda));

 

 

{

 

 

 

{

 

sum= (

i=i+1;

flag=

}

 

flag=

}

 

 

 

}

 

 

 

java.util.List<Integer> input =

java.io.BufferedReader br =

 

 

{

 

input.add(j);

 

}

java.util.Iterator<Integer> itr = input.iterator();

 

{

 

System.

 

}

 

 

}

 

}

import java.io.*;import

edwinfelix @ 23 Sep 2009 06:26 PM

import java.io.*;
import java.util.*;
class Z
{
public static void main(String[] args)
{
int z = 0, n;
int[] num;

n = getInt();
num = new int[n];

for(int i=0;i<n;i++)
num[i] = getInt();

for(int i=0;i<n;i++)
{
z=0;
for(int j=1;j<15;j++)
{
int x = (int)Math.pow(5.0,(float)j);
if(num[i] < x)
break;
z += num[i]/x;
}
System.out.println(z);
}
}
public static int getInt()
{
Scanner in = new Scanner(System.in);
int n = 0;
try
{
n = Integer.parseInt(in.next());
}
catch (Exception e)
{
return getInt();
}
return n;
}
}

 

 

 

 

Hi Admin...

can you tell me what is the porblem with this code.

Hi Admin... I've written

edwinfelix @ 23 Sep 2009 06:33 PM


Hi Admin...


I've written this code in java and compiled it in can you tell me what is the porblem with this code.


import java.io.*;
import java.util.*;
class Z
{
	public static void main(String[] args) 
	{
		int z = 0, n;
		int[] num;

		n = getInt();
		num = new int[n];

		for(int i=0;i< x)
					break;
				z += num[i]/x;
			}
			System.out.println(z);
		}
	}
	public static int getInt()
	{
		Scanner in = new Scanner(System.in);
		int n = 0;
		try
		{
			n = Integer.parseInt(in.next());
		}
		catch (Exception e)
		{
			return getInt();
		}
		return n;
	}
}

D:\Prg>java -jar

edwinfelix @ 23 Sep 2009 06:43 PM


D:Prg>java -jar Z.jar
5
34
793459
9874500
1000000000
389753098
7
198360
2468622
249999998
97438265

 

This is the output sample that my program generated. I'm getting NZEC Runtime Error every time i try to submit my JAR file

 

 

and

 

 

get a compilation error when i submit my source code.

Please read the FAQ and see

admin @ 23 Sep 2009 07:21 PM

Please read the FAQ and see the sample solutions at http://www.codechef.com/wiki

what is the maximum input

sampath kumar @ 28 Sep 2009 10:22 PM

what is the maximum input number we can take???

 

The range of N is specified

admin @ 29 Sep 2009 02:10 AM

The range of N is specified in the problem statement.

how can u see an already

satyajeet parida @ 29 Sep 2009 08:13 AM
how can u see an already submitted solution ???

To see your own solution,

admin @ 29 Sep 2009 02:08 PM

To see your own solution, click on the 'my submissions' link and you can then view the solution. Click on the plaintext link to view the solution in plaintext.

Hello, I've been working on a

ani_crypt @ 29 Sep 2009 03:17 PM

Hello,

I've been working on a solution in C++, but it appears that my solution is not optimised enough to beat the time limit.

If I'm correct, the time limit for this problem is 8s. Is this the time limit on the operation of validating my solution against all test input data sets? Or is it the limit for one given test input data?

If it's the latter, then I'm a bit confused because my solution seems to work for the worst case scenario of N=1000000000 in ~ 5.6 secs. Am I missing out on something here, or optimising my code is the way to go?

Also, is it any way possible to get my hands on the test input data sets you run against this problem's submitted solutions?

Well, currently it is not

admin @ 29 Sep 2009 04:36 PM

Well, currently it is not possible to give out the test input data. The time is for all the test cases. The total number of test cases is mentioned in the problem statement. So if it takes 5.6 seconds for the worst case, it will take much more for all the test cases combined.

@Aniruddha - If it isn't too

ani_crypt @ 29 Sep 2009 04:56 PM

@Aniruddha - If it isn't too much for asking, but can you share the worst-case scenario execution time observed for a valid submission?

It is possible to get that

admin @ 29 Sep 2009 09:45 PM

It is possible to get that information from the successful submissions block on this page. The accepted submissions are ordered by the amount of time they took for execution.

i am getting a runtime error

satyajeet parida @ 29 Sep 2009 10:44 PM

i am getting a runtime error when its working fine on my computer .... pls check this solution ...

my second submission is also

satyajeet parida @ 29 Sep 2009 10:53 PM

my second submission is also working fine but its saying now wrong answer .... pls help ...

Check the total number of

admin @ 29 Sep 2009 11:03 PM

Check the total number of test cases. Your array is too small. You don't need the array in the first place. In case you decide to stick with the array, declare it outside main. Declaring it inside main is causing a stack overflow.

@Aniruddha- in the successful

ani_crypt @ 30 Sep 2009 02:24 PM

@Aniruddha- in the successful submissions block, the times are for executing the entire collection of input data sets or is it for the worst-case scenario where there's only one input = 10^9?

The times are for executing

admin @ 30 Sep 2009 02:29 PM

The times are for executing the entire collection of input data sets.

My Program was running

hemashiki @ 30 Sep 2009 03:57 PM
My Program was running successfully, but it shows "compilation error" Can anyone tell me, whats wrong with my program??

@Hema Please take a look at

admin @ 30 Sep 2009 04:12 PM

@Hema Please take a look at the FAQ and Sample Solutions

hi can any one tell me what i

thrivikramarajarao @ 2 Oct 2009 05:46 PM
hi can any one tell me what i need to find in this prob., i am not understanding it plz help me in this.

The number of trailing 0s in

admin @ 2 Oct 2009 05:56 PM

The number of trailing 0s in n!

can someone pls tell me why

rampage @ 2 Oct 2009 11:48 PM

can someone pls tell me why i am getting a runtime error in this even though it works fine ?

#include<iostream.h>

int main()

{

long t,n,i,count[1000];

cin>>t;

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

{

count[i]=0;

cin>>n;

while(n>0)

{

n=n/5;

count[i]+=n;

}

}

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

{

cout<<count[i]<<"n";

}

return 0;

}

Have you tested it when there

triplem @ 3 Oct 2009 02:51 AM

Have you tested it when there are 100000 (or maybe 100010) test cases like mentioned?

What could be wrong with my

Adil_Jamil @ 3 Oct 2009 02:48 PM

What could be wrong with my code...??

 

Z[5]=1

 

All the given test cases give the right answer..

@Stephen-> Please Brother... can U suggest sumthin..?? This is simply destroying my will to try any other problem...

I have no idea what this is

johnny_null @ 7 Oct 2009 07:14 AM

I have no idea what this is looking for.

Hi, I wrote solution for this

jambunathan @ 11 Oct 2009 09:30 PM

Hi,

I wrote solution for this problem in ruby and the maximum value that could be given as input (1000000000) when tested in my comp gave the output in a fraction of a second.

 

The time shown as taken by the program is 4.58 seconds. but i somehow my solution got accepted. can you clalrify admin??

What do you want clarified?

triplem @ 12 Oct 2009 06:12 AM

What do you want clarified? The timit limit is 8 seconds, and you got less than that. Codechef is often slower than a home computer (though it sounds like you were only calculating the run time for one input anyway, when the real input can contain 100000 values.)

Hi!     I am Harini. I don't

harinithangirala @ 14 Oct 2009 08:11 PM

Hi!

    I am Harini. I don't know how to give code for the topics being asked by you. But i want to learn my coding perfectly. Can u suggest me some ways to improve my coding skills?

please check my solution.

devanshukatoch @ 18 Oct 2009 02:06 PM

please check my solution.

Can u please explain me some

devanshukatoch @ 19 Oct 2009 10:25 AM

Can u please explain me some time efficent approach to this pblem

 

I have a really short python

alterlife @ 19 Oct 2009 03:20 PM

I have a really short python proggy which seems to work for all testcases on my comp...

 

def nzeros(x):
n = 5
nz = 0
while round(x / n) > 0:
nz = nz + round(x / n)
n = n * 5

return nz


n = input()
for i in xrange(0,n):
print nzeros(input())

 

Any idea why is this failing :( .

I don't know Python, but

triplem @ 19 Oct 2009 04:38 PM

I don't know Python, but won't that fail for x=4?

round() returns a float. You

jcomeau_ictx @ 20 Oct 2009 11:56 AM

round() returns a float. You probably don't want floating point, you more likely want integer arithmetic that automatically discards any fractional part.

a couple of interesting

jcomeau_ictx @ 20 Oct 2009 01:40 PM

a couple of interesting observations, which others have probably seen too...

in the table of powers of five p: 5, 25, 625, 3125, etc.

(z(p[n]) * 100) + 25 = z(p[n+2])

for example, z(3125)= 781, and what follows in the table two slots later? 78125

this holds true ad infinitum, I believe, though I didn't carry it out very far yet.

the other observation is that z(n) approaches n/4 as n approaches infinity. I'm trying to determine empirically the exact nature of the curve, because shifting n right twice and subtracting a small correction factor would be far less expensive processor-wise than multiple divides.

wrote that wrong. it's

jcomeau_ictx @ 20 Oct 2009 11:21 PM

wrote that wrong. it's (z(p[n])*100)+25=p[n+2]

magic: all other things being

jcomeau_ictx @ 21 Oct 2009 11:09 AM

magic: all other things being equal, allocating a huge block of ram (e.g., int[] data = new int[1000000];) even if you don't use it for anything, and using the C# compiler (NOT the C#2) makes a program run much faster. no clue why this is. my most optimized assembly-language program ran in .11sec; a completely unoptimized C# program with this trick runs in .07sec.

#include<stdio.h> long long

toDu @ 21 Oct 2009 07:50 PM

#include<stdio.h>

long long int no_zero(long long int);
int main(void)
{ int k,i;
  long long int arr[400];
  
  scanf("%d",&k);
  for(i=0;i<k;i++)
  {
   scanf("%lld",&arr[i]);
  }
   for(i=0;i<k;i++)
   printf("%lldn",no_zero(arr[i]));

  
  exit(0);
  return 0;
}
long long int no_zero(long long int n)
{
 long long int i=5,j,sum=0;
 for(j=0;;j++)
 {
  if((n/i)!=0)
  {sum=sum+n/i;
   i=i*5;
   }
   else
   return sum;
  }
  }

 

can ne1 tell me wat is the error in it.. it shows run time err.. n when i reduce the arr it gives wrong ans.. but its working fine on my pc..

 

hi....friends. i am new to

ranjith @ 21 Oct 2009 08:27 PM

hi....friends. i am new to this site....can you help abt procedure...

 

You can get all the

admin @ 21 Oct 2009 09:00 PM

You can get all the information you need to start off at www.codechef.com/wiki

I am not able to understand

anu.simplyDgr8@gmail.com @ 27 Oct 2009 03:11 PM

I am not able to understand where am I going wron.its working properly in my compiler

Whats wrong in

anu.simplyDgr8@gmail.com @ 27 Oct 2009 03:17 PM

Whats wrong in this...

#include<stdio.h>
#include<stdlib.h>
int main(void)
{
//  clrscr();
// printf("Sidharth is my bro.");
int c,cnt=0,i=0;
long val[1000];
long reval[1000];

// clrscr();
scanf("%d",&c);

if(c>0)
{
while(cnt < c)
{
scanf("%ld",&val[cnt]);
//cnt++;
reval[cnt]=0;
while(val[cnt] >= 5)
{
reval[cnt]+= val[cnt]/5;
val[cnt]=val[cnt]/5;
}
cnt++;
}
printf("n");
//printf("Valuesn");
for(i=0;i<cnt;i++)
{
printf("%ldn",reval[i]);
}

}
printf("n");
system("PAUSE");
return 0;
}

system("pause") will not

admin @ 27 Oct 2009 03:34 PM

system("pause") will not work.

ok.removed

anu.simplyDgr8@gmail.com @ 27 Oct 2009 03:43 PM

ok.removed system("pause").any other mistake

I think you would need

admin @ 27 Oct 2009 03:54 PM

I think you would need #include<cstdio> and #include<cstdlib> You might want to switch over to gcc or a port of it like mingw

Actually, nothing is wrong

triplem @ 28 Oct 2009 04:46 PM

Actually, nothing is wrong with the header files (it is a C program, not a C++ program), and system("PAUSE") won't cause a correct solution to not be accepted (I often leave it in accepted solutions).

The problem is that there are way more than 1000 tests as mentioned in the problem statement. Try getting rid of the array altogether, just read in the value, find the result, and print it.

hey, plz tell me what z(N)

shreydutta.28 @ 1 Nov 2009 11:20 AM

hey, plz tell me what z(N) for N. i mean, is it the no. of 0's in N!(N factorial).??/???

plz,....some one clear ma doubt

It tells you in the problem

triplem @ 1 Nov 2009 01:28 PM

It tells you in the problem statement?

For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!.

@admin :: can sum1 plss tell

princeseth2006 @ 4 Nov 2009 11:23 PM

@admin :: can sum1 plss tell me wats wrong wid d CPP code i hv submitted??? the effort will be highly appreciated

How to submit the programs

shiv_indap @ 11 Nov 2009 02:40 AM

How to submit the programs using ruby, what is the name of the input file that I should give?

There is no input file. Use

triplem @ 11 Nov 2009 02:59 AM

There is no input file. Use standard input/output (see Sample Solutions).

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

harinderpal5 @ 11 Nov 2009 07:56 PM

#include<stdio.h>
int main(){
unsigned int t,a,s,i,*n,l;
scanf("%d",&t);
n = (int*)malloc(sizeof(int*) * t);
for(i=0;i<t;i++) {
scanf("%d",&n[i]);
}
for(i=0;i<t;i++) {
a=5;
s=0;
while(n[i]>a){
s=s+(n[i]/a);
a=a*5;
}
printf("n%d",s);
}

scanf("%d",&l);
return 0;
}


working fine on my gcc compiler but codechef compiler is giving wrong answer please help

first time here, disappointed

gtoal @ 12 Nov 2009 10:00 AM

first time here, disappointed to see that the scoring rewards people who optimise the I/O rather than any elegance in the algorithm itself. 

#include <stdio.h>
int z(int n) {
  int zeroes=0, powers_of_5=1;
  while ((n / 5) >= powers_of_5) {powers_of_5 *= 5; zeroes += n/powers_of_5;}
  return (zeroes);
}
int main(void) {
  int n, tests = (fscanf(stdin, "%d", &n),n);
  while (tests-- > 0) fprintf(stdout, "%dn", z((fscanf(stdin, "%d", &n),n)));
  return 0;
}
don't think I'll waste any more time here.

i'm lost3! = 6, no zeroes, so

titiwangsa @ 21 Nov 2009 05:25 PM

i'm lost

3! = 6, no zeroes, so 0, OK

60! = 8320987112741390000000000000000000000000000000000000000000000000000000000000000000
i'm not sure where the 14 comes from

and 100! = 93326215443944200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
i don't know how to get the 24

@ Titi Wangsa bin Damhore The

kathuria @ 21 Nov 2009 06:13 PM

@ Titi Wangsa bin Damhore

The idea is not to find N! .If you notice answer is same as the power of 5 in N!.

to calculate the power of 5 in N!  , calculate power of 5 in 1,2,3... N and sum them up.

Hope i was able to make it clear.

i'm still not clear. this is

titiwangsa @ 22 Nov 2009 01:49 AM

i'm still not clear.

this is my understanding

Z(3) = 0, because 3! is 6 and there are no zeroes

Z(4) = 0, because 4! is 24 and there are no zeroes.

Z(5) = 1, because 4! is 120 and there is one zero

i don't get how you get

Z(60) = 14, why?

based on the question, to my understanding, is to find "how many zeroes"

if H! = 315000000 (315 followed by 6 zeroes), then

Z(H) = 6

is this correct??

"For any positive integer N, Z(N) is the number of zeros at the end of the decimal form of number N!"

Z(8) = number of zeroes after 8!

8! = 40320, Z(8) = 1?

 

Everything you have said is

triplem @ 22 Nov 2009 02:55 AM

Everything you have said is correct. 60! is a number ending with 14 zeroes; it is not equal to the value you mentioned above.

dude i opened up excel and

titiwangsa @ 22 Nov 2009 04:58 AM

dude

i opened up excel

and keyed in

=FACT(60)

it shows up

8.32099E+81

ok

control+1

Category: Number

Decimal Places: 0

 

and this number shows up

8320987112741390000000000000000000000000000000000000000000000000000000000000000000

 

so i checked with google

it still says

8.32098711 × (10^81) = 8.32099E+81

 

so i made a table

of factorials in excel

this is what i got for the first 30 numbers

1
2
6
24
120
720
5040
40320
362880
3628800
39916800
479001600
6227020800
87178291200
1307674368000
20922789888000
355687428096000
6402373705728000
121645100408832000
2432902008176640000
51090942171709400000
1124000727777610000000
25852016738885000000000
620448401733239000000000
15511210043331000000000000
403291461126606000000000000
10888869450418400000000000000
304888344611714000000000000000
8841761993739700000000000000000
265252859812191000000000000000000

 

as you can see 30! has 18 zeroes.

so 60! can't have less, right?

i checked with google, it matches with the excel calculation up to 13!,

then google starts giving me xx.xx * 10 ^ xx notation

so i selected all the results again,

then press ctrl+1

Category: Scientific

Decimal Places: 7

 

Now it matches perfectly with google

it shows 30! as 2.6525286E+32

and google shows the same thing.

 

change it back to numbers

control+1

Category: Number

Decimal Places: 0

i get 265252859812191000000000000000000

so Z(30) = 18

 

 

 

All of those methods are

triplem @ 22 Nov 2009 05:10 AM

All of those methods are using approximate calculations, as they cannot store the exact representation. 21! = 51090942171709440000 and everything from that on is incorrect in your list.

(Try calculating 3^50 in excel. That obviously shouldn't end in any zeroes.)

ok. thanks for clearing that

titiwangsa @ 22 Nov 2009 05:17 AM

ok.

thanks for clearing that up.

I've written code in java and

rajkumargoel @ 22 Nov 2009 12:35 PM

I've written code in java and it gives the time limit exceeded .

what might be possible area wherein my code is consuming time?

Asking that shows you haven't

triplem @ 22 Nov 2009 03:20 PM

Asking that shows you haven't tested your code at all :P Read the input section then try a large test case and you will see exactly why it times out.

i tried with a large number

aliasnikhil @ 22 Nov 2009 07:39 PM

i tried with a large number of cases

and with large numbers and got the output well within 8 secs

but i am getting time limit exceeded on submittion

Admin, is something wrong

jcomeau_ictx @ 24 Nov 2009 10:38 AM

Admin, is something wrong with your database? The "successful submissions" haven't shown up for a few days now... am always getting the error "Oops, we couldn't seem to load the successfull submission. Try again soon."

Most other test problems pages aren't doing that, at least not consistently.

And when I posted that, I got

jcomeau_ictx @ 24 Nov 2009 10:40 AM

And when I posted that, I got some error message about not being able to send email... maybe you should put "fix the server software" as the bonus question on the December competition :^}

Yeah, it happened when they

triplem @ 24 Nov 2009 11:39 AM

Yeah, it happened when they switched servers. Have already pointed the former out here: http://discussed.codechef.com/showthread.php?goto=newpost&t=938

hey i need help with this

joelabreu @ 24 Nov 2009 09:04 PM

hey i need help with this program, I insert it and everything, if you try it in dev-cpp or any other compiler works, but when I put it here, I do not work, he always tells me runtime error, pls Help me improve the code

hey i need help with this

joelabreu @ 24 Nov 2009 09:05 PM

hey i need help with this program, I insert it and everything, if you try it in dev-cpp or any other compiler works, but when I put it here, I do not work, he always tells me runtime error, pls Help me improve the code:

#include<stdio.h>

 

long z(long n) { long c = 0; while ( n >= 5 ) { n /= 5; c += n; } return c; }

 

int main() {

long count[1000]; int t, x = 0; scanf("%d",&t);

while(x < t){ scanf("%ld",&count[x]); x++; } x = 0;

while(x < t){ printf("%ldn",z(count[x])); x++; }

return 0;

}

Why do you assume there will

triplem @ 25 Nov 2009 02:03 AM

Why do you assume there will be less than 1000 test cases when the problem says there will be more?

i always getting run-time

lalit.gera @ 28 Nov 2009 02:31 AM

i always getting run-time error??.....but it is working fine on my system.

i always get run-time

lalit.gera @ 28 Nov 2009 02:31 AM

i always get run-time error??.....but it is working fine on my system.

Then your system is not set

triplem @ 28 Nov 2009 05:15 AM

Then your system is not set up correctly. It is failing due to you creating the input stream twice when you shouldn't be.

Im getting right ouput for

TSK @ 28 Nov 2009 06:23 AM

Im getting right ouput for given inputs, Still getting WA, can anyone tell me what's wrong with my code?

 

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
long n;
cin>>n;
long Z=0;
int kmax=(log((double)n)/log((double)5));
for(int k=1;k<=kmax;k++)
Z = Z + floor(n/pow(5.0,k));
cout<<Z<<endl;
}
return 0;
}

 

 

You have not submitted that

triplem @ 28 Nov 2009 07:14 AM

You have not submitted that code in any of your submissions.

The reason code like that often won't work, though, is because you are using nonexact arithmetic; eg it is quite possible that pow(5.0,5) returns 3125.00000001, which would cause your program to give wrong answers. Same thing could occur with logs. You should always allow + adjust for error like that when using doubles, though it is much more advisable to avoid them completely in this problem.

Hi i am getting the following

anish7766 @ 28 Nov 2009 08:05 AM

Hi i am getting the following errors in a Dev-C++ 4.9.9.2

17 F:programscodecheffact.cpp new types may not be defined in a return type

17 F:programscodecheffact.cpp `main' must return `int'

Please anyone help....

I think i have done bt its

SaurabhS @ 28 Nov 2009 10:44 PM

I think i have done

bt its giving

"time limit exceeding"

 

what should i do??

Write a solution that doesn't

triplem @ 29 Nov 2009 02:32 AM

Write a solution that doesn't take too long. It should be obvious why your program is taking too long if you test it on the largest possible input.

The description doesn't

bballbackus @ 29 Nov 2009 10:35 AM

The description doesn't really make much sense...

What doesn't make sense to

triplem @ 29 Nov 2009 10:53 AM

What doesn't make sense to you?

The input section I guess. 

bballbackus @ 29 Nov 2009 11:59 AM

The input section I guess.  When it began talking about T I became confused

Oh wait, I think I get it

bballbackus @ 29 Nov 2009 12:11 PM

Oh wait, I think I get it now.  I thought that the input shown at the top correlated with the output.  I was killing myself trying to figure out Z(3) was equal to 14.

#include<stdio.h>#define N

new creater @ 29 Nov 2009 12:38 PM

#include<stdio.h>
#define N 100
main()
{
 int num1, num2, i, is2, is5;
 long a[N], j, k,j0;
 scanf("%d", &num1);
 num2 = num1;
 i = 0;
 is2 = 0;
 is5 = 0;
 while((num1)-->0){
  scanf("%d", &a[i]);
  k = 0;
  for(j=1; j<=a[i]; j++){
   j0 = j;
   while(j0%10==0){
    k++;
    j0 /= 10;
   }
   while(j0%5==0||j0%2==0){
    if(j0%5==0){
     is5++;
     j0 /= 5;
    }
    if(j0%2==0){
        is2++;
     j0 /= 2;
    }
   }
   if(is5>0&&is2>0){
    k++;
    is5--;
    is2--;
   }
  }
  a[i++] = k;
 }
 for(i=0; i<num2; i++)
  printf("%dn", a[i]);
}

It works well onmy

new creater @ 29 Nov 2009 12:42 PM

It works well onmy computer,but get a runtime error in the system.Please help!

@fagyuedong Same thing is

bballbackus @ 29 Nov 2009 01:04 PM

@fagyuedong

Same thing is happening to me... I hate how this place only accepts python 2.5 >_<

They're on python 3.1 now!! upgrade!

Grr... I fail to see how I am

bballbackus @ 29 Nov 2009 01:18 PM

Grr... I fail to see how I am getting a runtime error for this!

This is python by the way

while True:
    n = input()
    n = int(n)
    numberZeros = 0
    divisor = 5
    while(int(n/divisor)>0):
        numberZeros += int(n/divisor)
        divisor*=5
    print numberZeros 

@John - the input does

triplem @ 29 Nov 2009 02:06 PM

@John - the input does correspond with the output. It clearly says the first number in the input is the number of test cases, nowhere does it imply Z(3) = 14 (the first test case shows Z(3) = 0).

Your code has a while true loop, so will never terminate. Except once it is reaching the end of the file it is presumably encountering an error trying to convert the end of file character (or whatever input returns) to an integer.

@fangyuedong - Read the

triplem @ 29 Nov 2009 01:52 PM

@fangyuedong - Read the problem statement. Why would you define N to be 100 when it says specifically there will be around 100000 test cases?

@Stephen Thank you, I guess I

bballbackus @ 29 Nov 2009 02:23 PM

@Stephen


Thank you, I guess I was unclear.  I figured that this was like the last problem, in that it should just run forever. I know know what I was doing wrong.

@Stephen thank you, I have

new creater @ 29 Nov 2009 08:28 PM

@Stephen

thank you, I have improved the program according to your suggestion.And I get accepted.

why this function isn't

magiix @ 30 Nov 2009 02:23 AM

why this function isn't working??

int trailingzeros(int r)

{

int z=1,total=0;

while(pow(5,z)>=r)

{

total+=r/pow(5,z);

z++;

}

return total;

}

That code may well work; the

triplem @ 30 Nov 2009 06:27 AM

That code may well work; the code you submitted used r/pow(5,z)>1 rather than >=1. However, it quite probably won't work either, for the same reason I already mentioned several comments back. Read my comment containing the line 'The reason code like that often won't work'.

hi me and my friend were

vijay.iitm @ 30 Nov 2009 03:26 PM

hi me and my friend were trying this problem and came up with the following solution which works on my system but codechef shows it as wrong answer.

//############code##############
#include <iostream>
#include <math.h>
using namespace std;
int processnumber(int number){
int power=1;
int add;
int final=0;
while (1){
add = number/pow(5,power);
if (add != 0){
final = final + add;
power++;
}else{
break;
}
}
return final;
}

int main() {
cout << "Enter T: ";
int t;
cin >> t;
int *numbers;
numbers = new int[t];
for(int i =0;i<t;i++){
cin >> numbers[i];
}
for(int i =0;i<t;i++){
cout << processnumber(numbers[i])<< endl;
}
return 0;
}
//###############################

Hi, should the output look

ch4nd4n @ 30 Nov 2009 03:53 PM

Hi, should the output look exactly like how its mentioned in the problem statement?
I am not sure why my submission has not worked. During "Runtime" error, its unclear what went wrong.

 

@P. Vijay Kumar Raju -

triplem @ 30 Nov 2009 04:19 PM

@P. Vijay Kumar Raju - without even reading your algorithm, it is obvious why you are not getting the right result. Your output starts with 'Enter T'; the correct solution does not.

@Stephen Merriman: Well

magiix @ 30 Nov 2009 04:51 PM

@Stephen Merriman:

Well thanks i think you knew wat i was asking about although i copied the wrong source i needed to ask about :S


Btw this was the code i needed to ask about :

int trailingzeros(int r)
{
int z=1,total=0;
while(pow(5,z)>=1)
{
total+=r/pow(5,z);
z++;
}
return total;
}

oops copied the wrong code

magiix @ 30 Nov 2009 04:55 PM

oops copied the wrong code for the second time :
at last this is the one i was asking about :

int trailingzeros(int r)
{
int z=1,total=0;
while(r/pow(5,z)>=1)
{
total+=r/pow(5,z);
z++;
}
return total;
}

  Hello I just tried

Tyan Towers @ 30 Nov 2009 05:03 PM

 

Hello

I just tried submitting a piece of code, but it says runtime error (SIGSEGV). What does that mean and how to rectify it?

Here is my code:

#include <stdio.h>
int main()
{
int n,a,b,x,two,five;
scanf("%d",n);

int i;
for(i=0;i<n;i++)
{
scanf("%d",x);
//find the number of 5 factors
b=5;
a=0;
while(b<x)
{
a+=x/b;
b*=5;
}
printf("%d",b);
}
return 0;
}

one more doubt: is it ok to give my code here? sorry if its not :)

sorry! i realize my above

Tyan Towers @ 30 Nov 2009 06:58 PM

sorry! i realize my above mistake is in the scanf?

Well i rectified that and submitted it and it no longer shows runtime error. But my solution is still wrong! Can anyone please tell me what is wrong?

ah grrh so sorry I found some

Tyan Towers @ 30 Nov 2009 08:24 PM

ah grrh

so sorry

I found some more mistakes in my code

the while condition is 'b<=x' and the last printf is for a not b

Thank you once again

ah i finally got the correct

Tyan Towers @ 30 Nov 2009 08:29 PM

ah i finally got the correct answer. My mistake was that i didn't put a 'n' in my printf statement. So finally history was made with my first correct code submission!

Hey guys..Can any1 help me

predi @ 1 Dec 2009 12:33 AM

Hey guys..Can any1 help me with this code? Showing me 'Wrong Answer'

 

#include<stdio.h>
int main()
{
long n;
long k;


k=0;
scanf("%ld",&n);
if(n>=1l && n<1000000001l)
{
while(n/5>=1)
{
k=k+n/5;
n=n/5;
}
printf("%ldn",k);
}

return 0;
}

Try the sample input.

triplem @ 1 Dec 2009 01:59 AM

Try the sample input.

i seem to be getting a wrong

bhanuvrat @ 8 Dec 2009 08:50 PM

i seem to be getting a wrong answer for 1000000000 test case ... can any body tell me where I went wrong ...

the same as has been indicated by "gimme red" above....

hey guys .. can anybody

bhanuvrat @ 8 Dec 2009 08:53 PM

hey guys .. can anybody please share their output for 1000000 and 100000 with me ???

#include <iostream>using

Marine4Jesus@msn.com @ 9 Dec 2009 12:19 AM

#include <iostream>
using namespace std;

int main()
{
int n, temp ,d;
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> temp;
temp = temp/5;
d = temp;
while(1)
{
if(temp == 0)
break;
else
d = d + (temp=(temp/5));
}
cout << d;
}
return 0;
}

and why is this wrong?

can any body tell me what is

arun chauhan @ 9 Dec 2009 03:04 PM

can any body tell me what is problem with my code..... i am getting the result for your input cases right.....but uploading here it's showing me wrong answer..... and i am using gcc to compile my code...

@admin i too am facing the 

arun chauhan @ 9 Dec 2009 03:26 PM

@admin i too am facing the  problem of "gimmered".... and iam getting the output for a many probable test cases but it's still failing..... please help admin.... take a look at my last posted code....... and please tell me where am i having the problem.....

z(1000000000)=249999998

that is i think the exterme case.... and if it is correct then i don't think so there sould be any problem.....

Well, your last posted code

triplem @ 9 Dec 2009 03:39 PM

Well, your last posted code will quite obviously always fail on the 101th test case. I haven't looked past that.

@stephen merriman thank

arun chauhan @ 9 Dec 2009 07:00 PM

@stephen merriman thank you..... but after that i have increased the array size to your specification i.e i think

100000.... now also it seems to be getting failed........

 

Hallo! I'm new here, and I

rubeus.dumbledore @ 11 Dec 2009 02:07 PM

Hallo! I'm new here, and I got the right answers for the sample input, and I also seem to be getting the correct answer for the extreme case of 1000000000. Can anyone please help me out? thank you!

Here's my code -

 

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

int main()
{
long int count;
float *ptr ;
int *ptrres;
long int i=0;


scanf("%ld", &count);

ptr = (float*)malloc(count*(sizeof(*ptr)));
ptrres = (int*)malloc(count*(sizeof(*ptrres)));

if (ptr==NULL)
{
printf("nNo memory space availablen");
exit(0);
}


if (ptrres==NULL)
{
printf("nNo memory space availablen");
exit(0);
}

while (i<count)
{
scanf("%f",&ptr[i]);
i++;
}


for (i=0;i<count;i++)
{
while (((int)(ptr[i]/5))!=0)
{
ptrres[i] += ptr[i]/5;
ptr[i]/= 5;
}    
}    



for (i=0;i<count;i++)
printf("%dn",ptrres[i]);


return (0);
}

 

 

 

And I wonder why all the

rubeus.dumbledore @ 11 Dec 2009 02:20 PM

And I wonder why all the '/n's that I typed seem to appear simply as 'n's. Could that be the problem...? I read in the help section that there is some problem with the newline character in other operating systems. I'm using Ubuntu 9.04. Please let me know what the problem could be! :)

#include<stdio.h>

tushar.2905 @ 17 Dec 2009 06:53 PM

#include<stdio.h> #include<math.h> int main() { int t,i; unsigned long int n; scanf("%d",&t); for(i=0;i<t;i++) { scanf("%lu",&n); unsigned long int noz=0; int p,in=5; for(p=in,int po=1;p<n[i];po++,p=pow(in,po)) { noz=noz+(n[i]/p); } printf("%lu",&noz); } return 0; }

 

i dont know what is wrong help

@Tushar Could you please stop

admin @ 17 Dec 2009 07:00 PM

@Tushar Could you please stop spamming?

@Aniruddha: sorry for the off

Blitzkrieg @ 17 Dec 2009 07:12 PM

@Aniruddha: sorry for the off topic. Links to resnack practice problems are not visible but time started ticking. could you please look in to it.

yeah....please fix it

prsnk_DCoder @ 17 Dec 2009 07:16 PM

yeah....please fix it fast....

@aniruddha sorry i am new

tushar.2905 @ 18 Dec 2009 01:16 AM

@aniruddha sorry i am new here dont knew the format

i have sucessfully solved it now

Dear CodeChef Admin I have

srikant_ritolia @ 19 Dec 2009 01:00 PM

Dear CodeChef Admin

I have submitted the two solutions both gave time limit exceeded. I can see clearly that in Python the time limit is exceeding. But In my solution in C++ there is desired output within 8sec.

Even for the largest number 1000000000 the output is within 8sec. I have calculated the time.

Please see to my C++ solution submission.

 

 

On my computer you are taking

triplem @ 19 Dec 2009 01:25 PM

On my computer you are taking 8.4 seconds to process an input of the largest size. There could be 100000 possible inputs, so even if you were solving each of these in 7 seconds that would still be a total of about 194 hours to complete. Slightly more than the 8 second time limit. (And of course, Codechef tends to be 2-3 times slower than a home computer).

can anyone suggest me how to

srikant_ritolia @ 19 Dec 2009 03:51 PM

can anyone suggest me how to optimize my approach to not exceed time limit

 

i have used recursion to find

dhearora @ 21 Dec 2009 02:37 PM

i have used recursion to find the answer.my local answers are coming out correct .i m getting a runtime error when i submit..should i change my approach?

Hi i get this error for my

pritoj @ 22 Dec 2009 06:14 PM

Hi i get this error for my code

/sources/tested.cpp: In function 'int main()': /sources/tested.cpp:14: error: call of overloaded 'pow(int, int&)' is ambiguous /usr/include/bits/mathcalls.h:154: note: candidates are: double pow(double, double) /usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/cmath:360: note: long double std::pow(long double, int) /usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/cmath:356: note: float std::pow(float, int) /usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/cmath:352: note: double std::pow(double, int) /usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/cmath:348: note: long double std::pow(long double, long double) /usr/lib/gcc/i486-linux/4.0.1/../../../../include/c++/4.0.1/cmath:344: note: float std::pow(float, float) /sources/tested.cpp:15: warning: converting to 'int' from 'float'

 

13:for(int i=1;i>0;i++)
14:            {y=a/pow(5,i);
15:            x=floor(y);

what's wrong????

code runnin well on my

sumit.guha @ 23 Dec 2009 03:39 PM

code runnin well on my system...

i m using dev c++

 

but still your server reports a run time error

neither there is a divide by zero nor m i using much memory

admin plzz tell where m i goin wrng

You are missing return 0..

triplem @ 23 Dec 2009 03:59 PM

You are missing return 0..

@stephen:was that a reply to

pritoj @ 27 Dec 2009 09:31 AM

@stephen:was that a reply to my comment or sumit's????

i tested it for all the cases.... it runs fine on my pc..

@stephen:was that a reply to

pritoj @ 27 Dec 2009 09:31 AM

@stephen:was that a reply to my comment or sumit's????

i tested it for all the cases.... it runs fine on my pc..

and i do have the return 0;

sumits. The error message you

triplem @ 27 Dec 2009 11:04 AM

sumits.

The error message you are getting tells you exactly what the problem is. It can't choose which function to use since you are passing it two ints. You'll need to make at least one a floating point number, eg using 5.0 instead of 5.

yeah that's what i did and it

pritoj @ 28 Dec 2009 11:26 AM

yeah that's what i did and it gives me a wrong answer!!!!

it's running perfectly fine on my machine....

It gives wrong answer because

triplem @ 28 Dec 2009 12:35 PM

It gives wrong answer because it is wrong. For the same reason I have mentioned several times in the comments already; pow is a floating point function and you cannot expect it to be exact.

please tell me how to

rumi2752 @ 28 Dec 2009 02:13 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..

plz give me some correct test

piyushdd @ 30 Dec 2009 01:13 AM

plz give me some correct test data so that i can test my output

Try making some up yourself.

triplem @ 30 Dec 2009 01:58 AM

Try making some up yourself.

hey i tried submitting the

hiren.sharma @ 9 Jan 2010 03:03 PM

hey i tried submitting the program but it showed compiler error as could not find iostream.h. Program was written in C++, cant we use iostream as well

iostream.h has been

triplem @ 9 Jan 2010 03:19 PM

iostream.h has been deprecated for years; it is not a standard C++ header file and should never be used. Perhaps you meant to use <iostream> instead?

ok i got the error. . . thnx

hiren.sharma @ 9 Jan 2010 03:49 PM

ok i got the error. . . thnx but when i tried submitting the program it is showing runtime error. i hope there s nothing wrong wid the input i am takin. My Output is like this

 

3  //Total No. of Inputs

7 //First Number

1 //Ans

4 //Second Number

0 //Ans

16 // Third Number

3 //Ans

 

Is the way i am displaying the OUTUP Wrong ???

You aren't getting a runtime

triplem @ 9 Jan 2010 04:16 PM

You aren't getting a runtime error, you're getting wrong answer. You just have to output the answers, not the input. A quick look at your code shows you are printing all the answers together without any space between them at all; and your code will also probably fail for the same reasons as many other people mentioned above.

I tried this test and

sunnydays @ 10 Jan 2010 03:18 AM

I tried this test and received an error message

What error message?

triplem @ 10 Jan 2010 03:32 AM

What error message?

on my compiler gcc the

sahilsingla @ 10 Jan 2010 01:16 PM

on my compiler gcc the following code

#include<stdio.h>
int a,b;
int fn()
{
int n=0;
while(a>=5)
{
if(a%5!=0)
{
a--;
continue;
}
b=a;
a-=5;
while(b%5==0)
{
n++;
b=b/5;
}
}
printf("%dn",n);
return 1;
}
int main()
{
int in;
printf("Enter no of inputsn");
scanf("%d",&in);
while(in>=1)
{
in--;
scanf("%d",&a);
fn();
}
return 1;
}

is working well for large limit 1000000000 within 6 sec correctly bt on submission ans is coming out to be time limit exceeded...

plz help!

Your code is much too slow.

triplem @ 10 Jan 2010 01:25 PM

Your code is much too slow. It takes about 4 seconds on my computer to run a single input of 1000000000; there could be 100000 test cases. 4*100000 seconds is about 4.5 days, slightly more than the time limit ;)

ok .....i got your point and

sahilsingla @ 11 Jan 2010 10:33 PM

ok .....i got your point and my problem too........thanx for ur help :)

I am getting Time limit

rohitmanglik @ 13 Jan 2010 10:57 PM

I am getting Time limit exceeded error

<?php $var =fgets(STDIN,7); for($i=0;$i<$var;$i++) { $count=0; $input = fgets(STDIN,10); for($i=5;$i<=$input;$i+=5) { $tmp = $i; while($tmp%5==0) { $tmp=$tmp/5; $count++; } } echo $count; } ?>

 

How I can make it better?

this is my code can i get

pranay kumar @ 23 Jan 2010 01:27 AM

this is my code

can i get reason as to why this fails

#include<stdio.h>

#include<math.h>

int main()

{

long int n[100000];

int j,t,i,z,q;

scanf("%d",&t);

for(j=0;j<=t-1;j++)

scanf("%d",&n[j]);

for(j=0;j<=t-1;j++)

{

z=0;

q=2;

if(n[j]<=0)

z=0;

else

{

for(i=1;q>1;i++)

{

q=n[j]/pow(5,i);

z=z+q;

}

}

printf("%d",z);

}

return 0;

}

Your question has already

triplem @ 23 Jan 2010 02:23 AM

Your question has already been answered multiple times. Also, please read the FAQ.

its showing runtime error

ni8mare @ 23 Jan 2010 11:03 AM

its showing runtime error

My C++ code takes 2.7secs to

nutsnbolts @ 31 Jan 2010 02:08 PM

My C++ code takes 2.7secs to run ... I am surprised to see peoples codes taking only 0.05 seconds .. any tips how to reduce my time ...

i want 2 know the solution of

viv1somani @ 5 Feb 2010 09:27 AM

i want 2 know the solution of the problem..............?

You'll have to figure it out

triplem @ 5 Feb 2010 09:32 AM

You'll have to figure it out yourself.

This is ridiculous. I KNOW

Baruthakki @ 10 Feb 2010 07:49 AM

This is ridiculous. I KNOW the solution. I KNOW it works, and, under a milisecond. I just can't figure out what the .... the compiler expects from me (getting Runtime Error's). Thinking this is just the second easiest problem on here, I guess I'm either in the wrong place or I'm not advanced enough as I think I am.

.. and now that you have

triplem @ 10 Feb 2010 09:51 AM

.. and now that you have solved the problem, you KNOW the rather obvious mistake in your code ;) Make sure you always read the problem statement carefully; you had ignored an entire line of the input section, and your code didn't work on the sample input.

I am a newbie and this prog

flamy @ 10 Feb 2010 11:55 AM
I am a newbie and this prog made me thing for nearly 4 hrs and i got the prob now gonna work :P

what is the problem in my

jenis @ 11 Feb 2010 03:53 PM

what is the problem in my programm........

what is the problem in my

jenis @ 11 Feb 2010 03:56 PM

what is the problem in my programm........

#include<stdio.h> int

jenis @ 11 Feb 2010 05:12 PM
  1. #include<stdio.h>
  2. int factorial(int);
  3. void main()
  4. {
  5. int n,ans;
  6. printf("Enter the no whose factorial require:>");
  7. scanf("%d",&n);
  8. ans=factorial(n);
  9. printf("Ans=%d",ans);
  10. }
  11.  
  12. int factorial(int m)
  13. {
  14. int i,fact=1;
  15. for(i=1;i<=m;i++)
  16. fact=fact*i;
  17. return(fact);
  18. }
  19. what is problem in this programm?
  20. please tell me................... 

6. printf("Enter the no whose

zack @ 13 Feb 2010 07:17 PM

6.

printf("Enter the no whose factorial require:>"); <==== this is at least part of it. Erase it and try again.

I couldn't figure out how th

zack @ 13 Feb 2010 07:24 PM

I couldn't figure out how th z(n) is calculated. I understand it is the number of zeros at the end of the decimal, but how do I know how many are there?

@jenis Read the

triplem @ 14 Feb 2010 02:12 AM

@jenis Read the FAQ.

@Yekhezkel - that's the entire point of the problem, isn't it? I don't think anyone will just tell you the answer :P

But is it a known

zack @ 14 Feb 2010 05:22 PM

But is it a known mathematical function? I couldn't find enithing written about it anywere.

 

Besides, the thing here is to create the code, isn't it? If I'd understand what the code needs to do perhaps I coul'd write it...

My code is proper and I got

preethamms @ 14 Feb 2010 08:19 PM

My code is proper and I got the output in my local Compiler. For the sample input given I got the same sample output. But the codechef compiler is still showing "Runtime Error".

I've used several, several

Silly Rabit @ 19 Feb 2010 08:55 AM

I've used several, several test data sets.  my code is correct on my system Everytime.  However CodeChef gives me wrong answer everytime.... here is my code (C#)

********************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace factorial
{
class Program
{
static void Main(string[] args)
{
ArrayList numbers = new ArrayList();

string argument;
int z = 0;

do
{
argument = Console.ReadLine();
numbers.Add(Convert.ToInt32(argument));

} while (!string.IsNullOrEmpty(argument));

for (int i = 0; i < (int)numbers[0]; i++)
{
if (i != 0)
{
z = GetZerosCount(Convert.ToInt32(numbers[i]));
Console.WriteLine(z.ToString());
}
}
}

static int GetZerosCount(int n)
{
int count = 0;
while (n >= 5)
{
n /= 5;
count += n;
}

return count;
}
}
}

Please do not post code - see

triplem @ 19 Feb 2010 11:27 AM

Please do not post code - see the FAQ. That will also tell how you to test your code properly - you appear to already have figured this out, but your code was giving the wrong answer on every single test case, since you were not processing the last line in the file.

an easy problem.............

nirley.gupta @ 20 Feb 2010 10:06 PM

an easy problem............. just think a little you will get it

#include<stdio.h> int

willki @ 23 Feb 2010 10:54 PM
#include<stdio.h>
int main()
{
unsigned long int N[10],M,count[10]={0};
int n,i;
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%ld",&N[i]);
}
for(i=0;i<n;i++)
{
M=5;
while(N[i]/M)
{
count[i]=count[i]+(N[i]/M);
M=M*5;
}
}
for(i=0;i<n;i++)
{
printf("%ldn",count[i]);
}
getch();
return 0;
}
Is anything wrong here?

Please don't post code. Read

triplem @ 24 Feb 2010 09:27 AM

Please don't post code. Read the FAQ. (Various things wrong; eg using clrscr and getch, assuming there are only 10 test cases when the problem statement clearly says there are more..)

why am I getting wrong

anilkreddy @ 5 Mar 2010 08:34 PM

why am I getting wrong answer?

sumbission ID: 198629

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

praveenspecial @ 6 Mar 2010 09:26 AM

#include<stdio.h>
int main()
{
int n=1,i,j;
long k,c=0,pow=5;
scanf("%d",&n);
for(i=0;i<n;i++)
{
c=0;pow=5;
scanf("%ld",&k);
while(1)
{
if(pow<=k)
{
c+=(long)k/pow;
pow*=5;
}
else
break;
}
printf("%ldn",c);
}
return 0;
}

i am getting error as wrong answer i don't know for which test case my pgm is wrong can any one tell that

#include<stdio.h>#include<mal

nidhin varghese @ 9 Mar 2010 08:04 PM

#include<stdio.h>
#include<malloc.h>
void fact(int n);
main()
{
int t,i,*n;
scanf("%d",&t);
n=(int *)malloc(t * sizeof(int));
for(i=0;i<t;i++)
{
scanf("%d",&n[i]);
}                        
for(i=0;i<t;i++)
{
fact(n[i]);
}
}

void fact(int n)
{
int s=0;
while(n>5)
{
s=s+(n/5);
n=n/5;
//printf("%dt",n);
};
printf("%dn",s);
}

I have seen many solutions.

tijoforyou @ 9 Mar 2010 11:18 PM

I have seen many solutions. They are just awesome. But I would like to modify a few statements here and there and would like to know how it works. But it will be "stealing the code", right? So, is there any option, for me to test out all those optimizations, which I feel might work? Or is it free to do so? Admin, Please do reply.

Not gettin the programmm wht

tarunjain07 @ 10 Mar 2010 07:31 PM

Not gettin the programmm wht we have o do??

wht is it..o_0

can anyone tell me whats

flame06 @ 16 Mar 2010 08:13 AM

can anyone tell me whats wrong with my program....

i am sure i am getting the correct output....

See that section of the

triplem @ 16 Mar 2010 09:40 AM

See that section of the problem titled 'input'? Did you read it?

hey i'm getting a wrong

tkmandanna @ 19 Mar 2010 11:49 PM

hey i'm getting a wrong answer error for this code even tho i'm getting the correct output....

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

int x,y,a=0,c;

scanf("%d",&x);  
for(;x>0;x--)

{

scanf("%d",&y);
c=y/5;

a=c;

while(c>0)

{
a+=(c=c/5);

if(c==0)break;

}printf("n%dt",a);}

return 0;

}

 

@admin plz point out the error

Please do not post code here,

triplem @ 20 Mar 2010 02:07 AM

Please do not post code here, as mentioned in the FAQ.

You are not getting the correct output for a boundary test case which is one of the first ones you should have tested.

I hv written the following

mygaurav @ 20 Mar 2010 03:11 PM

I hv written the following code. It is giving runtime error but it is working well on  turbo c 4.5 comnpiler eveb for highest input 1000000000. Plz help

 

 

#include<stdio.h>

long int gif(float x)
{
return (long int)x;
}

long int power(long int i)
{
long int p=1,k;

for(k=0;k<i;k++)
p*=5;

return p;
}

long int exp5(long int n)
{
long int g,c=0,i=1;
while(g=gif((float)n/power(i)))
{
c+=g;
i++;
}
return c;
}

int main()
{
int tc,c=0,i;
long int noz[100],n;

scanf("%d",&tc);

while(c!=tc)
{
scanf("%ld",&n);

noz[c]=exp5(n);
c++;
}

for(i=0;i<tc;i++)
printf("%ldn",noz[i]);

return 0;
}

I hv written the following

mygaurav @ 20 Mar 2010 03:16 PM

I hv written the following code. It is giving runtime error but it is working well on  turbo c 4.5 comnpiler eveb for highest input 1000000000. Plz help

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

Read the section of the

triplem @ 20 Mar 2010 03:36 PM

Read the section of the problem called 'input'.

i have made some changes .

mygaurav @ 20 Mar 2010 05:48 PM

i have made some changes . Plz check still i am getting runtime error

 

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

plz help. even after making

mygaurav @ 20 Mar 2010 11:07 PM

plz help. even after making many changes regarding input specifications i hv not managed to get rid of RUNTIME ERROR.

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

Even in the question on Universe it was mentioned that take input upto EOF(as no of test cases were not specified) but process until 42 . But it accepted the solution if the input was taken upto 42

plz explain

Your code still makes a very

triplem @ 21 Mar 2010 02:17 AM

Your code still makes a very basic mistake. You are still ignoring one hugely important piece of information in the section called input. There are only 3 numbers in the input section, surely you can't simply ignore one of them.

As for your other question, read the FAQ about how the judge works.

I have incorporated all the

mygaurav @ 21 Mar 2010 12:00 PM

I have incorporated all the "three numbers" in my code ,tried different versions(test cases<100000,test cases<150000,test cases<1000000) but all in vain.

 

Also in the FAQ you referred to it was also mentioned that

If a program says a number will be between 0 and 100, it will be between 0 and 100. There is no need to write if (number>=0 && number<=100), or do anything in other cases.

also plz refer to the specific FAQ which satisfies the question on Universe(with reference to my previous question)

 

why do you then suggest to include this thing?

 

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

Adding lines to check the

triplem @ 21 Mar 2010 02:37 PM

Adding lines to check the input are within the expected bounds are not necessary.

Problem statement:

There is a single positive integer T on the first line of input (equal to about 100000).

Your code:

long int noz[100]

How exactly will 100000 input cases fit into that array?

thank u for helping me ......

mygaurav @ 21 Mar 2010 04:13 PM

thank u for helping me ......

code

tarunjain07 @ 31 Mar 2010 09:37 PM

code :

#include<iostream.h>
void main()
{
long int a,x,sum;
sum=0  ;
cin>>x;
while(x/5!=0)
{
a=x/5;
x=a       ;
sum=a+sum;

}
cout<<sum;

}

getting answers??

help me out really don knw wht to do??

same code in

tarunjain07 @ 31 Mar 2010 09:55 PM

same code in c

:

#include<stdio.h>
void main()
{
long int x,a,sum;
sum=0;
scanf("%li",&x);
while(x/5!=0)
{
a=x/5;
x=a       ;
sum=a+sum;

}
printf("%li",sum);

}

is giving run time error...??

screwed up man...wht is dis....??

can any one help me out??

FAQ

triplem @ 1 Apr 2010 05:04 AM

FAQ

This problem should be in the

javadecoder @ 13 Apr 2010 11:01 PM

This problem should be in the too easy section!

how do you handle large

virang1 @ 14 Apr 2010 09:46 AM

how do you handle large number like 1000000000 ?

its coming runtime error pls

ni8mare @ 20 Apr 2010 03:41 PM

its coming runtime error pls help

Read the FAQ.

triplem @ 20 Apr 2010 04:24 PM

Read the FAQ.

Does anybody who already has

tin.pavlinic @ 24 Apr 2010 05:08 AM

Does anybody who already has got it right know what Z(1000000000) is? It would help me in trying to find my bug.


Dear admin,   I am first

natraj09 @ 29 Apr 2010 09:06 AM

Dear admin,

 

I am first timer. I have tried with almost all boundary conditions. I ma not sure for what input values I am getting wrong answer. Can you please share the test data or help me with what values my program is failing.

Your code gives the wrong

triplem @ 29 Apr 2010 10:44 AM

Your code gives the wrong answer for the sample input. Read the input format again.

Also, if you want to use doubles in your program rather than calculate exactly with ints, you must allow for small errors. Doubles are not exact, so you could easily get a result like 4.999999973 for a calculation where the exact result is 5 - you are then taking the floor of this number and getting 4 instead of 5.

Thanks Stephen. The problem

natraj09 @ 29 Apr 2010 11:48 AM

Thanks Stephen. The problem was not for using doubles in program but was for not considering the first input as the number of lines to be read.

Can anyone suggest something

indraneel @ 8 May 2010 08:28 PM

Can anyone suggest something to reduce the time limit of my code please

here is my code.

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

P.S:I have really tried very much.

I also read the FAQ, but no help

 

thanks in advance

Admin getting internal error

neena2k @ 9 May 2010 10:28 PM

Admin

getting internal error occured in system

Sorry this is the

indraneel @ 10 May 2010 10:56 PM

Sorry

this is the code

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

Can you please point out

neena2k @ 11 May 2010 12:04 PM

Can you please point out whats wrong with the solution. I get the necessary output on my local system

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

 

No you don't. The first line

triplem @ 11 May 2010 12:36 PM

No you don't. The first line of the sample output is 0. Yours is some text.

How about this one..removed

neena2k @ 11 May 2010 01:34 PM

How about this one..removed the text

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

Your answer is in the FAQ.

triplem @ 11 May 2010 04:40 PM

Your answer is in the FAQ.

Thanks Stephen..I found out

neena2k @ 11 May 2010 07:59 PM

Thanks Stephen..I found out what was wrong..

#include<stdio.h> #include

sweetpooh23 @ 12 May 2010 09:09 PM

#include<stdio.h>

#include <stdlib.h>

void main()

{

long i,j,t,s,r;

long *n,*z;

scanf("%ld",&t);

n = (long *)malloc(t*sizeof(long));

z = (long *)malloc(t*sizeof(long));

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

{

scanf("%ld",&n[i]);

z[i]=0;

r=n[i]-(n[i]%5);

if(r%10!=0)

{

s=r;

while(s%5==0)

{

s=s/5;

z[i]++;

}

r=r-5;

}

for(j=r;j>0;j=j-10)

{

s=j;

while(s%10==0)

{

s=s/10;

z[i]++;

}

while(s%5==0)

{

s=s/5;

z[i]++;

}

s=j-5;

while(s%5==0)

{

s=s/5;

z[i]++;

}

}

}

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

printf("%ldn",z[i]);

}

plzzz...suggest some way to optimize the code...

While submitting, i am

pankaj.aeon @ 14 May 2010 07:35 PM

While submitting, i am getting a pop up message that solution to this problem cannot be submitted currently..

Why is it so?

Time Limit

pankaj.aeon @ 14 May 2010 08:31 PM

Time Limit Exceeded......

 

To make sure i did an stress testing on my code..

I made an in.txt file with

100000 in the 1st line

and then

1000000000

in the next 100000 lines..

 

I hope u understand that this is the maximum input case..

My machine is taking hardly any time to generate the out.txt file with the answer 249999998, 100000 times..

 

How could i get "Time Limit Exceeded"??

@pankaj   u r using in.txt

devendra088 @ 14 May 2010 08:56 PM

@pankaj

 

u r using in.txt for input but how u can be sure that input file name will be in.txt

 

thats why u r getting Time limit exceed

1 of 2
next ›

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

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 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 algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm 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 programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were 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 challenges 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 coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

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. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.