|
|
back to boardwhi it is wrong? help me please var i,j,n:integer; sg:longint; x,k,l:byte; s:string; procedure readdata; begin read (n,s); end; procedure solve; begin k:=length(s)-1; sg:=n; x:=1; for j:=1 to n do begin if n mod k <> 0 then begin if (j=n)and(x=2) then sg:=sg*(n mod k) else if (n>=j*k)and((n-j*k)<>1)and((n-j*k)<>0) then begin x:=2; sg:=sg*(n-j*k); end else if sg=0 then begin sg:=0; exit; end; end else begin if (j=n)and(x=2) then sg:=sg*k else if (n>=j*k)and((n-j*k)<>1)and((n-j*k)<>0) then begin sg:=sg*(n-j*k); x:=2; end else if sg=0 then begin sg:=0; exit; end; end; end; end; procedure print; begin writeln (sg); end; begin readdata; solve; print; end. I think this is gonna help... > var i,j,n:integer; > sg:longint; > x,k,l:byte; > s:string; > > procedure readdata; > begin > read (n,s); > end; > > procedure solve; > begin > k:=length(s)-1; > sg:=n; > x:=1; > for j:=1 to n do > begin > if n mod k <> 0 then > begin > if (j=n)and(x=2) then > sg:=sg*(n mod k) {Here !!!} > else > if (n>=j*k)and((n-j*k)<>1)and((n-j*k)<>0) then > begin > x:=2; > sg:=sg*(n-j*k); {And here you take the same number eventuallu!!!!!, look at my example....} { > end > else > if sg=0 then > begin > sg:=0; > exit; > end; > end > else > begin > if (j=n)and(x=2) then > sg:=sg*k > else > if (n>=j*k)and((n-j*k)<>1)and((n-j*k)<>0) then > begin > sg:=sg*(n-j*k); > x:=2; > end > else > if sg=0 then > begin > sg:=0; > exit; > end; > end; > end; > end; > > procedure print; > begin > writeln (sg); > end; > begin > readdata; > solve; > print; > end. > > Hi! I think, you take one and same number two times For example, if input is: 5 !!! You output 20, but the wright answer is 10. > "if (j=n)and(x=2) then > sg:=sg*(n mod k)" I think, you dont need this - take it out and will have Accepted(dont forget that you have used this and when "n%k=0"!!!!! HAve a look at this Idea, too: t=n; while(t>0) do Begin dec(t,k); if (t>1) n=n*t; End; writeln(n); Bye!!! |
|
|