var i:longint; begin read(i); writeln(i-1); end. It is impossible that you got AC. Try this Input: 15 Correct answer: 2 Your answer: 14 Read prob attentively. The LEAST l is wanted. because you need to output MINIMAL L, and you outputs Maximal L long int c,i; int main () { cin>>c; cout<<c-1<<endl; return 0; } Sorry, dudes, I've understand! because you need to output MINIMAL number Edited by author 16.04.2007 12:51 Edited by author 09.04.2007 20:21 Try some prime number near to 100 000 000 :P Yours is O(k), you can do O(sqrt(k)) with the same idea, just think a bit :PPP What's wrong? WA#11 [code deleted] I thought, it's correct. Edited by author 23.03.2007 13:21 Oh, I've found my mistake... AC now. P. S. Try test 116882 Sorry!!!!HOW I can do BY O(sqrt(k))? P.S.ANSWER FOR test 116882 IS 58440? Edited by author 23.03.2007 17:16 THANK TO KIRILL(ArcSTU) FOR PASCAL VERSION OF THIS PROBLEM!!!!! Edited by author 14.04.2007 23:18 Edited by author 14.04.2007 23:20 After rejudgment I lost AC. But I think my algo is correct... What's problem? I don't understand why my solution is uncorrect. Answer is (k % 3) + 2 . Please give me some test. It isn't a correct formula, for example test: 7 The right answer is 6, not 3. And test: 10 The answer is 4, not 3; Good Luck) Edited by author 08.02.2007 10:58 [code deleted] Edited by moderator 09.06.2006 13:40 Look at that: while (b&& i<=(long) sqrt(l)+1); You must use sqrt((double)l). P.S. For more information see FAQ 10x, finally I got Accepted :) [code deleted] Edited by moderator 08.06.2006 08:24 My algorithm is linear but it takes TL on test 10. I measured the time of execution on my computer and it's less than 0.0001 s. for biggest cases. Even for big prime numbers? Yup, you're right. 10x for the help pls tell me where i am mistaking in my logic: if u take l=k-1 then whatever the first player takes the second player wins but on test 3 it says wrong anwser Admin's tests aren`t wrong! (it is strange why they didn't ban you:). If you read task attentive, you may saw next thing: if there are few correct L, you must write smallest of them. And as you understand, L=k-1 is not smallest in all tests. is it possible to be answer zore? how? program ex; var now,i,l,k:longint; begin readln(k); now:=k; for i:=3 to trunc(sqrt(100000000)) do if k mod i=0 then begin now:=i; break; end; writeln(now-1); end. > program ex; > var > now,i,l,k:longint; > begin > readln(k); > now:=k; > for i:=3 to trunc(sqrt(100000000)) do > if k mod i=0 then begin now:=i; break; end; > writeln(now-1); > end. > what will you do when K is a prime number? For example,k=3. program ex; var now,i,l,k:longint; begin readln(k); now:=k; for i:=3 to 10000 do {trunc(sqrt(100000000))=10000} if k mod i=0 then begin now:=i; break; end; writeln(now-1); end. I have tried. Itself so thought. Wrong answer. I did so at the first time but got WA Try this test 1999966 the correct answer is 999982 but the result of your program is 1999965 ... In this problem, trunc(sqrt(100000000)) isn't a right limit. We should use (k div 2)+1 for the high limit,isn't it? is not. trunc(sqrt(k)) - rigth limit var n,l,i:longint; begin readln(n); l:=n-1; if ((n mod 2)=0) and (n div 2>2) then l:=n div 2-1; for i:=2 to trunc(sqrt(n)) do if n mod (i+1)=0 then begin l:=i; break end; writeln(l) end. When I tried to solve this problem, at first I wrote N^3 solution using Dynamic Programming: if we're seeing a piece with length = K and trying solve problem with any L, let's take K-1, K-2, ..., K-L buttons and see, whether second player win with new K and old L. But now we say, that it's first player, because we have already solve this problem for first player and K-1, K-2, ..., 2, 1. That's all. Here is my code: {$APPTYPE CONSOLE} program buttons; var a: array[1..5000] of integer; k: integer; i, j, t, x: integer; f: boolean; function FirstWins(k, l: integer): boolean; begin Result := (l >= k) or (l < a[k]); end; begin read(k); a[1] := 0; a[2] := 1; for i := 3 to k do begin for j := 2 to k-1 do begin f := true; for t := i-j to i-1 do begin if not FirstWins(t, j) then begin f := false; break; end; end; if f then begin a[i] := j; break; end; end; end; write(k); end. ----------------- After that I observed law: if k mod 3 = 0, print 2 else print n-1: read(k); if (k mod 3 = 0) then write(2) else write(k-1); But I got WA in test 6. Where is my mistake? Where is mistake in DP-logic? Edited by author 15.08.2005 10:25 Excuse me, I have already found the bug. It was in function: function FirstWins(k, l: integer): boolean; begin Result := (l >= k) or (l <> a[k]); end; I had AC this problem, but now I have minus for this problem. Why??? Don't know... Maybe you should write to the admins of the site Yes, some submits were rejudged due to problems with compilators. Please resubmit your program. 1999966 should output 999982 but 1999965 is also correct Problem statement says: "If there are several those numbers L, you should write the least." so the answer is 999982, not 1999965. var i,k:longint; ok:boolean; begin ok:=false; readln(k); for i:=trunc(sqrt(k)) downto 2 do if ((k mod i)=0) and (not ok) then begin ok:=true; writeln(i); end; if not ok then writeln(k-1); end. I have got A.C.,but my programme doesn't contain the possibility of output "0". Actually,you won't find any situation that the number l doesn't exist,for you can take l=k-1,at least. So should the problem contain this sentence "If there are no such numbers, you are to write 0 to the standard output. "??? the answer doesn't contains 0. program permutation; var m,p : array [1..1000] of word; N,i,j : integer; k : longint; quit : boolean; Begin readln(N); for i := 1 to N do read(p[i]); for i := 1 to n do m[i]:=p[i]; k:=1; quit := false; while true do begin j:=0; repeat j:=j+1; quit := m[j]=j; until (quit=false) or ((i=n) and (m[i]=i)); if quit then break; k:=k+1; for i := 1 to n do m[i] := p[m[i]]; end; writeln(K); end. #include <iostream.h> #include <math.h> int main(void) { int K; int ind = 1; int L = 0;
cin >> K; if( !(K % 2) ) { while( (!(K % 2)) && (K > 4) ) K /= 2; L = K - 1; ind = 0; }; for(int i = 3 ; ( i <= ceil( sqrt(K) ) ) && ind ; ++i) { if( !(K % i) ) { L = i - 1; ind = 0; }; }; if( (K != 1) && (L == 0) ) L = K - 1; cout << L; return 0; }; //I compiled it under bc 3.0, vc 7.0, vc 6.0 //Please HELP My program got CE at the first,but when I changed sqrt(K) to sqrt((double)K),it got AC.Maybe you can have a try,good luckЈЎ > > > If L=a then the second player can take such numbers b(1<=b<=a) of buttons, that ((first_player_take)+b)=(a+1). > If L=a then the second player can take such numbers b(1<=b<=a) of > buttons, that ((first_player_take)+b)=(a+1). #include <iostream.h> #include <math.h> void main() { float k; long i,l; cin>>k; {l=int(k)-1; for(i=2;i<=sqrt(k)+4;i++) if ((k/i==int(k/i))&& (i>=3) ){l=i- 1;break;}; cout<<l;}; } always get wrong answer > #include <iostream.h> > #include <math.h> > void main() > { float k; > long i,l; > cin>>k; > {l=int(k)-1; > for(i=2;i<=sqrt(k)+4;i++) if ((k/i==int(k/i))&& (i>=3) ){l=i- > 1;break;}; > cout<<l;}; > } Though I don't know what wrong about sqrt(k)+4 but I use k/2 instead of sqrt(k) and Get a AC try it please . I haven't learn C++ but I learned C and Pascal Why don't you use % in you program? If there is no % in C++ you can try this (k/i-int(k/i)<1e-15) and i think you'll get AC then. At last I give you a AC C program; #include<math.h> void main() { long n; long i; scanf("%ld",&n); for (i=3;i<=n/2;i++) if (!(n%i)) {printf("%ld\n",i-1);exit();} printf("%ld\n",n-1); } Good luck next time.:-) > > #include <iostream.h> > > #include <math.h> > > void main() > > { float k; > > long i,l; > > cin>>k; > > {l=int(k)-1; > > for(i=2;i<=sqrt(k)+4;i++) if ((k/i==int(k/i))&& (i>=3) ){l=i- > > 1;break;}; #include<iostream.h> #include<math.h> int k,l; void main() { cin>>k; long temp=(long)floor(sqrt(k))+2;//be care about k=4 for(long i=3;i<=temp;i++) if(k%i==0){ cout<<i-1; return; } if(k%2==0)k/=2; cout<<k-1; } > > cout<<l;}; > > } > Though I don't know what wrong about > sqrt(k)+4 but > I use k/2 instead of sqrt(k) and Get a AC > try it please . > I haven't learn C++ but I learned C and Pascal > Why don't you use % in you program? > If there is no % in C++ you can try this > (k/i-int(k/i)<1e-15) > and i think you'll get AC then. > At last I give you a AC C program; > #include<math.h> > void main() > { > long n; > long i; > scanf("%ld",&n); > for (i=3;i<=n/2;i++) > if (!(n%i)) > {printf("%ld\n",i-1);exit();} > printf("%ld\n",n-1); > } > Good luck next time.:-) > |
|