FactorialProblem code: FCTRL |
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
| Date: | 2008-12-01 |
| Time limit: | 8s |
| 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 |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
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.

Fetching successful submissions

I've given the above mentioned input and I am getting the output mentioned, but when I submit, it says 'Wrong Answer'
@aravind kesiraju
check the output for N=5 in your program
Note: plz rember the special case for N = 5^t
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?
Is there any way by which we can know input for which output is incorrect .
@all
Please take a look at the FAQ at http://blog.codechef.com/2009/06/29/frequently-asked-questions/
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?
Why can't I see other's solution to this problem.... whereas I can view other's solutions for problems like Enormous input test?
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...
@admin : well thanks for the reply... but why is this so?
@ayan cause it wouldnt be fun if all the answers were available :)
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??
I submitted a solution in C , and it works perfectly on my computer...but I got wrong answer as a result. Any ideas?
@preity Please read the FAQ and the sample program for JAVA at www.codechef.com/help
@Nishant The test cases are consistent. If you are getting WA, you would have to recheck your algorithm or implementation :)
why are there 7 example inputs and only 6 outputs?
@Aaron Err.. The first one is actually number of test cases and not exactly an input in the sense you mean :-)
Can ne1 put up a tutorial fr dis 1!
i submitted the solution is java but it says time limit exceeded
pls have a look into it and help
@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 ?
can ne1 explain wat is Z(N) in detail say N 4 wat will be z?
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
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.
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!
i got it to be submiteed...thanks anyways....
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
This could be because your algorithm has a bug.
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
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.
@gimme red - what's your answer for 1000000000?
I'm getting
Z(99999999999) = 249999989
Z(1000000000) = 249999998
I checked manually seems like the right answer
dear admin,
Could you please share the test data for which you think my program doesnt work.
GR
@gimme red - pm your code to me on the forum (leppy) and I'll take a look for you.
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.
@Prunthaban
Thanks..i had same doubts about that!!
Dear Admin,
I think I found the test case its failing on. Z(0) = 0; I fixed it but its still failing
GR
The problem says N>=1, so that was never going to be in the input.
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......
What is not clear in the problem statement?
@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
I can't see others' solutions for this problem.
The solutions to this problem are not public as of now. So, you won't be able to see any of the solutions.
#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",
i removed conio.h header from my prg, still it is giving runtime error . It is running successfully in turbo c.
You shouldn't print anything other than the required things. Don't print "Enter sample input"
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.
The FAQ says that the conio header has to be removed. still, i am getting a runtime error
#include main() { long int
respected sir i have an
#include int main() {
i have an error like runtime
The function main() should
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
It says on the page itself..
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
but on the home page its
what does that actually mean
The august mini challenge
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
@admin : can we have some
It tells you how large the
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
@admin :: can sum1 plss tell
hi everybody, I am have
You won't be able to
hi everybody, I am have
You don't have to calculate
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
#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
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
@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
6 is not one of the values you should calculate an answer for. Read the 'input' section.
@Stephen : Oops!!! Thanks u
@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
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
How could 6 isn't one of the numbers to be calculated when 1 <= N <= 1000000000?
Never mind, I'm an idiot.
Never mind, I'm an idiot.
what is maximunm that can be
what is maximunm that can be given as input
It says that in the section
It says that in the section titled 'Input', surprisingly enough.
#include<stdio.h> int
#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;
You are missing a return 0;
HI, I'm getting an NZEC
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
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
@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
#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
sorry for pasting the
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
@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
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
@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
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
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......
thanx......
Hello every one! I dont
plz tell me what's wrong with
why no one is responding to
Don't use the plain-text
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?
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
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
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
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
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
Please read the FAQ and see the sample solutions at http://www.codechef.com/wiki
what is the maximum input
what is the maximum input number we can take???
The range of N is specified
The range of N is specified in the problem statement.
how can u see an already
To see your own solution,
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
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
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
@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
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
i am getting a runtime error when its working fine on my computer .... pls check this solution ...
my second submission is also
my second submission is also working fine but its saying now wrong answer .... pls help ...
Check the total number of
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
@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
The times are for executing the entire collection of input data sets.
My Program was running
@Hema Please take a look at
@Hema Please take a look at the FAQ and Sample Solutions
hi can any one tell me what i
The number of trailing 0s in
The number of trailing 0s in n!
can someone pls tell me why
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
Have you tested it when there are 100000 (or maybe 100010) test cases like mentioned?
What could be wrong with my
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
I have no idea what this is looking for.
Hi, I wrote solution for this
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?
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
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.
please check my solution.
Can u please explain me some
Can u please explain me some time efficent approach to this pblem
I have a really short python
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
I don't know Python, but won't that fail for x=4?
round() returns a float. You
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
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
wrote that wrong. it's (z(p[n])*100)+25=p[n+2]
magic: all other things being
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
#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
hi....friends. i am new to this site....can you help abt procedure...
You can get all the
You can get all the information you need to start off at www.codechef.com/wiki
I am not able to understand
I am not able to understand where am I going wron.its working properly in my compiler
Whats wrong in
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
system("pause") will not work.
ok.removed
ok.removed system("pause").any other mistake
I think you would need
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
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)
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
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
@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
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
There is no input file. Use standard input/output (see Sample Solutions).
#include<stdio.h>int main(){
#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
first time here, disappointed to see that the scoring rewards people who optimise the I/O rather than any elegance in the algorithm itself.
i'm lost3! = 6, no zeroes, so
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
@ 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
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
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
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
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
ok.
thanks for clearing that up.
I've written code in java and
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
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
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
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
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
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
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
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
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
i always getting run-time error??.....but it is working fine on my system.
i always get run-time
i always get run-time error??.....but it is working fine on my system.
Then your system is not set
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
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
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
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
I think i have done
bt its giving
"time limit exceeding"
what should i do??
Write a solution that doesn't
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
The description doesn't really make much sense...
What doesn't make sense to
What doesn't make sense to you?
The input section I guess.
The input section I guess. When it began talking about T I became confused
Oh wait, I think I get it
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
#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
It works well onmy computer,but get a runtime error in the system.Please help!
@fagyuedong Same thing is
@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
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
@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
@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
@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
@Stephen
thank you, I have improved the program according to your suggestion.And I get accepted.
why this function isn't
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
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
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
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 -
@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
@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
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
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
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
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
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
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.
Try the sample input.
i seem to be getting a wrong
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
hey guys .. can anybody please share their output for 1000000 and 100000 with me ???
#include <iostream>using
#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
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
@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
Well, your last posted code will quite obviously always fail on the 101th test case. I haven't looked past that.
@stephen merriman thank
@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
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
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>
#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
@Tushar Could you please stop spamming?
@Aniruddha: sorry for the off
@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
yeah....please fix it fast....
@aniruddha sorry i am new
@aniruddha sorry i am new here dont knew the format
i have sucessfully solved it now
Dear CodeChef Admin I have
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
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
can anyone suggest me how to optimize my approach to not exceed time limit
i have used recursion to find
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
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
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..
You are missing return 0..
@stephen:was that a reply to
@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
@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
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
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
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
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
plz give me some correct test data so that i can test my output
Try making some up yourself.
Try making some up yourself.
hey i tried submitting the
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
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
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
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
I tried this test and received an error message
What error message?
What error message?
on my compiler gcc the
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.
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
ok .....i got your point and my problem too........thanx for ur help :)
I am getting Time limit
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
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
Your question has already been answered multiple times. Also, please read the FAQ.
its showing runtime error
its showing runtime error
My C++ code takes 2.7secs to
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
i want 2 know the solution of the problem..............?
You'll have to figure it out
You'll have to figure it out yourself.
This is ridiculous. I KNOW
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
.. 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
what is the problem in my
what is the problem in my programm........
what is the problem in my
what is the problem in my programm........
#include<stdio.h> int
6. printf("Enter the no whose
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
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
@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
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
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
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
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.............
an easy problem............. just think a little you will get it
#include<stdio.h> int
Please don't post code. Read
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
why am I getting wrong answer?
sumbission ID: 198629
#include<stdio.h>int main(){
#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
#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.
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
Not gettin the programmm wht we have o do??
wht is it..o_0
can anyone tell me whats
can anyone tell me whats wrong with my program....
i am sure i am getting the correct output....
See that section of the
See that section of the problem titled 'input'? Did you read it?
hey i'm getting a wrong
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,
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
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
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
Read the section of the problem called 'input'.
i have made some changes .
i have made some changes . Plz check still i am getting runtime error
http://www.codechef.com/viewsolution/212731
plz help. even after making
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
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
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
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 ......
thank u for helping me ......
code
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
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
FAQ
This problem should be in the
This problem should be in the too easy section!
how do you handle large
how do you handle large number like 1000000000 ?
its coming runtime error pls
its coming runtime error pls help
Read the FAQ.
Read the FAQ.
Does anybody who already has
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
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
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
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
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
Admin
getting internal error occured in system
Sorry this is the
Sorry
this is the code
http://www.codechef.com/viewsolution/240115
Can you please point out
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
No you don't. The first line of the sample output is 0. Yours is some text.
How about this one..removed
How about this one..removed the text
http://www.codechef.com/viewsolution/241514
Your answer is in the FAQ.
Your answer is in the FAQ.
Thanks Stephen..I found out
Thanks Stephen..I found out what was wrong..
#include<stdio.h> #include
#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]);
}
While submitting, i am
While submitting, i am getting a pop up message that solution to this problem cannot be submitted currently..
Why is it so?
Time Limit
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
@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