Page 3 of 5
Posted: Tue Feb 03, 2004 12:53 pm
by Dominik Michniewski
I think 0<=M<=N
Best regards
DM
Posted: Sun Aug 22, 2004 5:17 am
by bugzpodder
so how does this solution work for finding the last non-zero digit of n!:
[cpp]#include <stdio.h>
#include <string.h>
#define MAXN 1000
long a[MAXN], l;
void a_div_5(void)
{
int i, plus;
plus = 0;
for (i=0; i<l; i++) {
a = a*2+plus;
plus = a/10;
a = a%10;
}
if (plus>0) a[l++] = plus;
l--;
for (i=0; i<l; i++) a = a[i+1];
}
int main(void)
{
char buffer[MAXN];
long mod[20]={1,1,2,1,4,2,2,4,2,3,4,4,3,4,1,3,3,1,3,2};
int result, n, i, plus, j, one;
FILE *f, *g;
f = stdin;
g = stdout;
while ( fscanf(f, "%s", buffer) != EOF) {
l = strlen(buffer);
for (i=0; i<l; i++) a = buffer[l-1-i] - '0';
one = l==1 && a[0]==1;
result = 1;
while (l>0) {
if (l==1) result = result * mod[a[0]] % 5;
else result = result * mod[a[0] + 10*(a[1]%2) ] % 5;
a_div_5();
}
if (one || result%2==0) fprintf(g, "%d\n", result);
else fprintf(g, "%d\n", result+5);
}
return 0;
}
[/cpp]
a_div_5 is obvious, but what is mod??[cpp][/cpp]
Posted: Sat Nov 13, 2004 3:40 pm
by Amir Aavani
dear Riyad
I dont think your code has any chance for getting accepted
becuase
you want to avoid having 0 by using ,
mult=mult%100000;
which when i> 100000 , for example i=1000000> 20000000 then mult will be 0 and ...
also in your while where x= mult%10, i cant understand why you use a loop, ???
I think the easiest brute force alg is:
S:= 1;
C2:= 0
C5:= 0;
for i:= m+ 1 to n do
j:= i;
while j mod 2= 0 do
j:= j div 2;
Inc (C2);
while j mod 5= 0 do
j:= j div 5;
Inc (C5);
S:= S* (j mod 10);
if C2> C5 then
S:= (S* 2^ (C2- C5) )mod 10
else
S:= (S* 5^ (C5- C2) )mod 10
But I this alg may encounter time limit!
Amir
10212: Online judge fails
Posted: Sun Nov 28, 2004 1:03 pm
by G
I solved 10212, but I had some problems with the online judge. If someone supervising the
online judge reads this, then check my submissions numbered 3110597 and 3110602. These
two C programs are essentially the same, except that in one of them I have a "const char *"
having a length 36365 characters (and the online judge says: Wrong Answer), in the other
I broke this string up in a "const char * []", in which every string is of length 220 or less (and
the online judge accepts it). The problem is most likely in the long line, but if I compile these
on my machine, then there is no problem in compiling or running and they give the same answer
for several hundred thousand randomly generated and some special case input. Please,
correct the online judge or the submission method (I do not know which went wrong): I
used the WWW form to submit these programs, and I uploaded the program so there should
not be a copy-paste error in it.
TIA:
Geza
10212: Online judge fails
Posted: Wed Dec 01, 2004 8:44 am
by G
I solved 10212, but I had some problems with the online judge. If someone supervising the
online judge reads this, then check my submissions numbered 3110597 and 3110602. These
two C programs are essentially the same, except that in one of them I have a "const char *"
having a length 36365 characters (and the online judge says: Wrong Answer), in the other
I broke this string up in a "const char * []", in which every string is of length 220 or less (and
the online judge accepts it). The problem is most likely in the long line, but if I compile these
on my machine, then there is no problem in compiling or running and they give the same answer
for several hundred thousand randomly generated and some special case input. Please,
correct the online judge or the submission method (I do not know which went wrong): I
used the WWW form to submit these programs, and I uploaded the program so there should
not be a copy-paste error in it.
TIA:
Geza
10212 The Last Non-zero Digit
Posted: Sat Dec 04, 2004 12:03 am
by Antonio Ocampo
Could someone give me a hint ???
I got TLE with my purely force brute algorithm.
Thx in advance...

Posted: Fri Mar 18, 2005 5:24 pm
by I LIKE GN
We must factorize n! into this form: 2^i * 3^j * 5^k * 7^l, and find the corresponding i, j, k, and l.
eg, n=10.
10! = 1.2.3.4.5.6.7.8.9.10 = 2^7.3^4.5^2.7^1
and we also know the lastdigit of 2^k, 3^k, 5^k, and 7^k; 0<=k<=p.
If you still confuse how to factorize it, I will gratefull to tell you more...
Also i amm confused of that...
Scorpion
Please would u be a bit more specific

10212
Posted: Sat Jan 21, 2006 7:43 pm
by ckm111
Sorry~~
Can sombody give me test case ~
thanks~~
Posted: Sun Feb 05, 2006 9:22 am
by Wei-Ming Chen
65 8
2
5564 665
2
4445 2222
4
7895 2144
2
10 10
8
54 0
0
0 0
0
87 5
4
545454 66666
4
78965 78956
6
Posted: Wed Aug 16, 2006 1:58 am
by JaviGS
You're Wrong. Output for cases n 0 should be 1 instead of 0.
Posted: Sat Jun 16, 2007 5:45 pm
by emotional blind
I am getting WA.. I need a lot of inputs and outputs
Can any one help me..
Code: Select all
CODE removed after getting accepted
or can any one tell me for which input my program produces wrong output?
thanks
Posted: Tue Jun 19, 2007 5:09 am
by hamedv
I'm geting WA.
pleeze tell me my code bug.
Code: Select all
#include <stdio.h>
int n, m, i, a, x;
int main()
{
while (scanf("%d%d", &n, &m) != EOF)
{
a = 1;
for (i = n-m+1; i <= n; i++)
{
a *= i;
while (a % 10 == 0) a /= 10;
a %= 10;
}
printf("%d\n", a);
}
}
Posted: Tue Jun 19, 2007 5:49 am
by emotional blind
Integer Overflow
Posted: Tue Jun 19, 2007 6:03 am
by hamedv
I used "long long" but I got TLE
Posted: Tue Jun 19, 2007 6:06 am
by mf
emotional blind wrote:Integer Overflow
I don't think so.
hamedv, try N=126 M=2. Compute the right answer by hand and compare with your program's output.