LOGIN
  • Register
  • Forgot Password?

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
  • COMPETE
    • March Algorithm Challenge
    • February Algorithm Challenge
    • January Algorithm Challenge
    • December Algorithm Challenge
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • About Directi
    • Careers
Home » Problems (easy) » Factorial

Factorial

Problem code: FCTRL

  • Submit
  • All Submissions

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


Date: 2008-12-01
Time limit: 8

s
Source limit: 50000
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 TEXT


  • Submit

Comments

  • Login or Register to post a comment.

Aravind Kesiraju - 11th Jun,2009 23:24:18.

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

kinjal dixit - 14th Jun,2009 07:46:46.

@aravind kesiraju

check the output for N=5 in your program

Rooparam Choudhary - 14th Jun,2009 19:18:18.

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

Debidatta Dwibedi - 28th Jun,2009 06:05:23.

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 Srivastava - 28th Jun,2009 17:48:33.

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

Aniruddha - 29th Jun,2009 19:24:50.

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

James Vinett - 3rd Jul,2009 03:16:55.

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?

Ayan Sengupta - 17th Jul,2009 16:38:43.

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

Directi Admin - 17th Jul,2009 17:01:21.

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...

Ayan Sengupta - 17th Jul,2009 17:51:45.

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

Directi Admin - 17th Jul,2009 17:55:57.

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

preity - 25th Jul,2009 20:28:49.

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??

Nishant - 26th Jul,2009 01:35:05.

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

Directi Admin - 26th Jul,2009 07:57:57.

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

Directi Admin - 26th Jul,2009 07:58:43.

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

Aaron Martin - 29th Jul,2009 07:31:40.

why are there 7 example inputs and only 6 outputs?

Prunthaban K - 29th Jul,2009 14:08:08.

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

Dibyendu Das - 30th Jul,2009 04:31:30.

Can ne1 put up a tutorial fr dis 1!

Abhra Sadhukhan - 30th Jul,2009 12:46:38.

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

Directi Admin - 30th Jul,2009 18:34:42.

@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 ?

devang doshi - 3rd Aug,2009 07:47:13.

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

gimme red - 5th Aug,2009 19:28:18.

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

Directi Admin - 5th Aug,2009 19:36:29.

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.

Nithin - 5th Aug,2009 23:11:26.

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!

Nithin - 5th Aug,2009 23:19:49.

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

gimme red - 6th Aug,2009 02:05:22.

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

Directi Admin - 6th Aug,2009 02:17:15.

This could be because your algorithm has a bug.

gimme red - 6th Aug,2009 05:03:21.

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

Directi Admin - 6th Aug,2009 18:33:41.

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 - 7th Aug,2009 05:03:17.

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

gimme red - 7th Aug,2009 08:26:50.

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

gimme red - 7th Aug,2009 12:19:30.

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

leppyr64 - 7th Aug,2009 17:52:04.

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

Directi Admin - 7th Aug,2009 18:45:11.

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.

Sheikh Aman - 8th Aug,2009 14:25:17.

@Prunthaban

Thanks..i had same doubts about that!!

gimme red - 9th Aug,2009 06:40:33.

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

Stephen Merriman - 9th Aug,2009 11:37:50.

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

Pranav Tripathi - 9th Aug,2009 15:09:37.

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......

Directi Admin - 9th Aug,2009 20:11:51.

What is not clear in the problem statement?

Dustin Graham - 10th Aug,2009 09:43:53.

@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 - 17th Aug,2009 16:22:10.

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

Directi Admin - 17th Aug,2009 16:24:40.

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

Ivneet kaur - 17th Aug,2009 17:57:06.

#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",

Ivneet kaur - 17th Aug,2009 17:58:13.

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

Directi Admin - 17th Aug,2009 18:00:14.

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

Directi Admin - 17th Aug,2009 18:03:41.

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.

Ivneet kaur - 17th Aug,2009 18:21:16.

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

#include main() { long int

nitish - 18th Aug,2009 14:47:44.
#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 - 18th Aug,2009 14:51:15.
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() {

shailesh - 19th Aug,2009 14:55:23.
#include int main() { return 0; }

i have an error like runtime

nitish - 21st Aug,2009 12:49:50.
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

Aniruddha (Codechef) - 21st Aug,2009 13:21:44.

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

Nishant bulchandani - 21st Aug,2009 16:34:34.
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..

Stephen Merriman - 21st Aug,2009 16:36:49.

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

Nishant bulchandani - 21st Aug,2009 16:37:22.
do i have to register somewhere for the august mini challenge?

but on the home page its

Nishant bulchandani - 21st Aug,2009 16:43:20.
but on the home page its saying..it is in progres...

what does that actually mean

Nishant bulchandani - 21st Aug,2009 16:45:54.
what does that actually mean

The august mini challenge

Aniruddha (Codechef) - 21st Aug,2009 16:57:48.

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

abhijeet kumar - 22nd Aug,2009 10:12:55.
@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

abhijeet kumar - 22nd Aug,2009 10:31:54.
@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

Stephen Merriman - 22nd Aug,2009 10:35:41.

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

abhijeet kumar - 22nd Aug,2009 11:04:15.
oops .. my mistake

@admin :: can sum1 plss tell

abhijeet kumar - 24th Aug,2009 21:05:22.
@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

Kartik Dadwal - 26th Aug,2009 14:08:20.
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

Stephen Merriman - 26th Aug,2009 17:29:30.
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

Kartik Dadwal - 27th Aug,2009 15:55:08.
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

Aniruddha (Codechef) - 27th Aug,2009 16:00:04.

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

Rahul Agarwal - 29th Aug,2009 09:44:10.

#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

Stephen Merriman - 29th Aug,2009 09:58:39.

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

Abhishek Sharma - 29th Aug,2009 23:17:28.

@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

Stephen Merriman - 30th Aug,2009 03:46:11.

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

@Stephen : Oops!!! Thanks u

Abhishek Sharma - 30th Aug,2009 17:05:28.

@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

Rahul Agarwal - 31st Aug,2009 09:36:20.

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

Jacob Howarth - 1st Sep,2009 21:15:57.

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

Never mind, I'm an idiot.

Jacob Howarth - 1st Sep,2009 21:30:40.

Never mind, I'm an idiot.

what is maximunm that can be

gaurav gupta - 4th Sep,2009 09:53:17.

what is maximunm that can be given as input

It says that in the section

Stephen Merriman - 4th Sep,2009 10:09:56.

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

#include<stdio.h> int

ranjeet kumar - 4th Sep,2009 23:59:22.

#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;

Aniruddha (Codechef) - 5th Sep,2009 14:28:48.

You are missing a return 0;

 HI, I'm getting an NZEC

Abhijit K - 6th Sep,2009 03:30:05.

 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

Abhishek kumar - 7th Sep,2009 01:35:21.

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

Aniruddha (Codechef) - 7th Sep,2009 14:14:47.

@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

Evuru.sasidhar - 7th Sep,2009 19:47:15.

#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 - 10th Sep,2009 19:59:38.

 

  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 - 10th Sep,2009 20:20:23.

 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

Ashish - 10th Sep,2009 21:02:56.

@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 - 10th Sep,2009 23:58:10.

 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

Ashish - 11th Sep,2009 02:35:20.

@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 - 11th Sep,2009 12:30:02.

 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

Stephen Merriman - 11th Sep,2009 12:43:08.

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 - 11th Sep,2009 13:39:06.

 thanx......

Hello every one! I dont

venkata vineel - 13th Sep,2009 01:51:12.
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

venkata vineel - 13th Sep,2009 01:55:15.
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

venkata vineel - 13th Sep,2009 01:57:38.
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

Aniruddha (Codechef) - 13th Sep,2009 19:54:42.

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?

venkata vineel - 15th Sep,2009 14:19:09.

 

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

venkata vineel - 15th Sep,2009 14:21:09.

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

Edwin Felix - 23rd Sep,2009 18:26:51.

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

Edwin Felix - 23rd Sep,2009 18:33:50.


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

Edwin Felix - 23rd Sep,2009 18:43:12.


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

Aniruddha (Codechef) - 23rd Sep,2009 19:21:40.

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

what is the maximum input

k.sampath kumar - 28th Sep,2009 22:22:37.

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

 

The range of N is specified

Aniruddha (Codechef) - 29th Sep,2009 02:10:49.

The range of N is specified in the problem statement.

how can u see an already

Satyajeet Parida - 29th Sep,2009 08:13:58.
how can u see an already submitted solution ???

To see your own solution,

Aniruddha (Codechef) - 29th Sep,2009 14:08:47.

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

Anirvan Majumdar - 29th Sep,2009 15:17:10.

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

Aniruddha (Codechef) - 29th Sep,2009 16:36:13.

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

Anirvan Majumdar - 29th Sep,2009 16:56:14.

@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

Aniruddha (Codechef) - 29th Sep,2009 21:45:51.

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 - 29th Sep,2009 22:44:55.

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

my second submission is also

Satyajeet Parida - 29th Sep,2009 22:53:02.

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

Check the total number of

Aniruddha (Codechef) - 29th Sep,2009 23:03:55.

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

Anirvan Majumdar - 30th Sep,2009 14:24:42.

@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

Aniruddha (Codechef) - 30th Sep,2009 14:29:22.

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

My Program was running

Hema Elango - 30th Sep,2009 15:57:35.
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

Aniruddha (Codechef) - 30th Sep,2009 16:12:37.

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

hi can any one tell me what i

thrivikramarajarao - 2nd Oct,2009 17:46:54.
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

Aniruddha (Codechef) - 2nd Oct,2009 17:56:04.

The number of trailing 0s in n!

can someone pls tell me why

ankit kumar - 2nd Oct,2009 23:48:18.

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

Stephen Merriman - 3rd Oct,2009 02:51:01.

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

What could be wrong with my

Adil Jamil - 3rd Oct,2009 14:48:11.

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 - 7th Oct,2009 07:14:35.

I have no idea what this is looking for.

Hi, I wrote solution for this

jambunathan - 11th Oct,2009 21:30:57.

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?

Stephen Merriman - 12th Oct,2009 06:12:09.

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

harini - 14th Oct,2009 20:11:15.

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.

Devanshu - 18th Oct,2009 14:06:10.

please check my solution.

Can u please explain me some

Devanshu - 19th Oct,2009 10:25:39.

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

 

I have a really short python

Jeevan John - 19th Oct,2009 15:20:49.

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

Stephen Merriman - 19th Oct,2009 16:38:42.

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

round() returns a float. You

John Comeau - 20th Oct,2009 11:56:35.

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

John Comeau - 20th Oct,2009 13:40:48.

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

John Comeau - 20th Oct,2009 23:21:14.

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

magic: all other things being

John Comeau - 21st Oct,2009 11:09:09.

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

Toshi R Singhal - 21st Oct,2009 19:50:31.

#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 - 21st Oct,2009 20:27:31.

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

 

You can get all the

Aniruddha (Codechef) - 21st Oct,2009 21:00:00.

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

I am not able to understand

Anne - 27th Oct,2009 15:11:42.

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

Whats wrong in

Anne - 27th Oct,2009 15:17:25.

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

Aniruddha (Codechef) - 27th Oct,2009 15:34:36.

system("pause") will not work.

ok.removed

Anne - 27th Oct,2009 15:43:14.

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

I think you would need

Aniruddha (Codechef) - 27th Oct,2009 15:54:39.

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

Stephen Merriman - 28th Oct,2009 16:46:22.

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)

Shrey Dutta - 1st Nov,2009 11:20:07.

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

Stephen Merriman - 1st Nov,2009 13:28:00.

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

prince - 4th Nov,2009 23:23:48.

@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 - 11th Nov,2009 02:40:26.

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

Stephen Merriman - 11th Nov,2009 02:59:11.

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

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

Harinderpal Singh - 11th Nov,2009 19:56:07.

#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

Graham Toal - 12th Nov,2009 10:00:07.

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

Titi Wangsa bin Damhore - 21st Nov,2009 17:25:24.

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

ramthegreatcv - 21st Nov,2009 18:13:30.

@ 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

Titi Wangsa bin Damhore - 22nd Nov,2009 01:49:25.

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

Stephen Merriman - 22nd Nov,2009 02:55:01.

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

Titi Wangsa bin Damhore - 22nd Nov,2009 04:58:05.

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

Stephen Merriman - 22nd Nov,2009 05:10:53.

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

Titi Wangsa bin Damhore - 22nd Nov,2009 05:17:32.

ok.

thanks for clearing that up.

I've written code in java and

rajkumar - 22nd Nov,2009 12:35:32.

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

Stephen Merriman - 22nd Nov,2009 15:20:14.

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

nikhil upadhyay - 22nd Nov,2009 19:39:34.

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

John Comeau - 24th Nov,2009 10:38:25.

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

John Comeau - 24th Nov,2009 10:40:03.

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

Stephen Merriman - 24th Nov,2009 11:39:03.

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

hey i need help with this

Joel Abreu - 24th Nov,2009 21:04:30.

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

Joel Abreu - 24th Nov,2009 21:05:26.

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

Stephen Merriman - 25th Nov,2009 02:03:25.

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 - 28th Nov,2009 02:31:08.

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

i always get run-time

lalit gera - 28th Nov,2009 02:31:29.

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

Then your system is not set

Stephen Merriman - 28th Nov,2009 05:15:17.

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

Sushil Chejara - 28th Nov,2009 06:23:09.

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

Stephen Merriman - 28th Nov,2009 07:14:14.

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

Anish Kumar - 28th Nov,2009 08:05:56.

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

Saurabh Srivastava - 28th Nov,2009 22:44:25.

I think i have done

bt its giving

"time limit exceeding"

 

what should i do??

Write a solution that doesn't

Stephen Merriman - 29th Nov,2009 02:32:54.

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

John Backus - 29th Nov,2009 10:35:43.

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

Hmm... //

John Backus - 29th Nov,2009 10:37:18.

Hmm...

//

What doesn't make sense to

Stephen Merriman - 29th Nov,2009 10:53:07.

What doesn't make sense to you?

The input section I guess. 

John Backus - 29th Nov,2009 11:59:27.

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

Oh wait, I think I get it

John Backus - 29th Nov,2009 12:11:43.

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

fangyuedong - 29th Nov,2009 12:38:14.

#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

fangyuedong - 29th Nov,2009 12:42:28.

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

@fagyuedong Same thing is

John Backus - 29th Nov,2009 13:04:02.

@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

John Backus - 29th Nov,2009 13:18:53.

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

Stephen Merriman - 29th Nov,2009 14:06:06.

@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

Stephen Merriman - 29th Nov,2009 13:52:53.

@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

John Backus - 29th Nov,2009 14:23:46.

@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

fangyuedong - 29th Nov,2009 20:28:48.

@Stephen

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

why this function isn't

Karim - 30th Nov,2009 02:23:50.

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

Stephen Merriman - 30th Nov,2009 06:27:01.

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

P. Vijay Kumar Raju - 30th Nov,2009 15:26:21.

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

ckr - 30th Nov,2009 15:53:13.

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 -

Stephen Merriman - 30th Nov,2009 16:19:34.

@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

Karim - 30th Nov,2009 16:51:35.

@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

Karim - 30th Nov,2009 16:55:04.

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

Thrupthi Ann Jphn - 30th Nov,2009 17:03:08.

 

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

Thrupthi Ann Jphn - 30th Nov,2009 18:58:05.

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

Thrupthi Ann Jphn - 30th Nov,2009 20:24:31.

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

Thrupthi Ann Jphn - 30th Nov,2009 20:29:22.

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

Umesh Chug - 1st Dec,2009 00:33:09.

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.

Stephen Merriman - 1st Dec,2009 01:59:07.

Try the sample input.

i seem to be getting a wrong

Anuvrat Parashar - 8th Dec,2009 20:50:58.

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

Anuvrat Parashar - 8th Dec,2009 20:53:36.

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

#include <iostream>using

Nicholas Blasingame - 9th Dec,2009 00:19:07.

#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 - 9th Dec,2009 15:04:23.

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 - 9th Dec,2009 15:26:56.

@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

Stephen Merriman - 9th Dec,2009 15:39:47.

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 - 9th Dec,2009 19:00:58.

@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

Ramakrishna Padmanabhan - 11th Dec,2009 14:07:12.

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

Ramakrishna Padmanabhan - 11th Dec,2009 14:20:25.

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 Aggarwal - 17th Dec,2009 18:53:27.

#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

Aniruddha (Codechef) - 17th Dec,2009 19:00:22.

@Tushar Could you please stop spamming?

@Aniruddha: sorry for the off

Blitzkrieg - 17th Dec,2009 19:12:38.

@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

DCoder - 17th Dec,2009 19:16:39.

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

@aniruddha sorry i am new

Tushar Aggarwal - 18th Dec,2009 01:16:50.

@aniruddha sorry i am new here dont knew the format

i have sucessfully solved it now

Dear CodeChef Admin I have

Srikant Ritolia - 19th Dec,2009 13:00:54.

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

Stephen Merriman - 19th Dec,2009 13:25:57.

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 - 19th Dec,2009 15:51:49.

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

 

i have used recursion to find

Dheeraj Arora - 21st Dec,2009 14:37:50.

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 Hades - 22nd Dec,2009 18:14:48.

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 - 23rd Dec,2009 15:39:23.

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..

Stephen Merriman - 23rd Dec,2009 15:59:56.

You are missing return 0..

@stephen:was that a reply to

Pritoj Hades - 27th Dec,2009 09:31:23.

@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 Hades - 27th Dec,2009 09:31:39.

@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

Stephen Merriman - 27th Dec,2009 11:04:02.

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 Hades - 28th Dec,2009 11:26:29.

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

Stephen Merriman - 28th Dec,2009 12:35:40.

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

Mazharul Islam - 28th Dec,2009 14:13:29.

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

piyush dungarwal - 30th Dec,2009 01:13:39.

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

Try making some up yourself.

Stephen Merriman - 30th Dec,2009 01:58:07.

Try making some up yourself.

hey i tried submitting the

Hiren - 9th Jan,2010 15:03:35.

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

Stephen Merriman - 9th Jan,2010 15:19:50.

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 - 9th Jan,2010 15:49:32.

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

Stephen Merriman - 9th Jan,2010 16:16:14.

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

Patricia - 10th Jan,2010 03:18:01.

I tried this test and received an error message

What error message?

Stephen Merriman - 10th Jan,2010 03:32:35.

What error message?

on my compiler gcc the

sahil singla - 10th Jan,2010 13:16:31.

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.

Stephen Merriman - 10th Jan,2010 13:25:06.

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

sahil singla - 11th Jan,2010 22:33:24.

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

I am getting Time limit

Rohit Manglik - 13th Jan,2010 22:57:00.

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 - 23rd Jan,2010 01:27:52.

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

Stephen Merriman - 23rd Jan,2010 02:23:24.

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

its showing runtime error

Satyajeet Parida - 23rd Jan,2010 11:03:48.

its showing runtime error

My C++ code takes 2.7secs to

Raison - 31st Jan,2010 14:08:30.

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

vivek somani - 5th Feb,2010 09:27:24.

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

You'll have to figure it out

Stephen Merriman - 5th Feb,2010 09:32:29.

You'll have to figure it out yourself.

This is ridiculous. I KNOW

Akin Ugur - 10th Feb,2010 07:49:40.

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

Stephen Merriman - 10th Feb,2010 09:51:17.

.. 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

Fl@my - 10th Feb,2010 11:55:10.
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 - 11th Feb,2010 15:53:55.

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

what is the problem in my

jenis - 11th Feb,2010 15:56:52.

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

#include<stdio.h> int

jenis - 11th Feb,2010 17:12:20.
  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

Yekhezkel Yovel - 13th Feb,2010 19:17:04.

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

Yekhezkel Yovel - 13th Feb,2010 19:24:04.

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

Stephen Merriman - 14th Feb,2010 02:12:56.

@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

Yekhezkel Yovel - 14th Feb,2010 17:22:05.

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

Preetham M S - 14th Feb,2010 20:19:23.

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

Sadmihir rajen - 19th Feb,2010 08:55:45.

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

Stephen Merriman - 19th Feb,2010 11:27:23.

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 - 20th Feb,2010 22:06:37.

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

#include<stdio.h> int

wilfred - 23rd Feb,2010 22:54:59.
#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

Stephen Merriman - 24th Feb,2010 09:27:40.

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

Anil Kumar Reddy - 5th Mar,2010 20:34:40.

why am I getting wrong answer?

sumbission ID: 198629

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

praveen kumar - 6th Mar,2010 09:26:36.

#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 - 9th Mar,2010 20:04:00.

#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.

Tijo Jose - 9th Mar,2010 23:18:34.

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

Tarun Jain - 10th Mar,2010 19:31:27.

Not gettin the programmm wht we have o do??

wht is it..o_0

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

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.

  • About CodeChef
  • About Directi
  • CEO's Corner
  • Careers
  • feedback@codechef.com
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
Sponsors
The time now is: