in my accepted program I checked if i <= 10000 but printed i + k, so for test like 6 0 2 it printed 10001 but I think correct answer should be 0 your test is incorrect, cause n,m,k bigger , then 0 Good problem, thanks to author! 4 5 1 196 6 10 1 4656 15 27 4 0 2 4 1 40 2 4 2 24 2 4 3 24 2 4 20 24 2 4 4 30 2 4 5 30 23 24 5 0 1 4 6 385 3 4 50 66 Edited by author 13.06.2014 14:08 Oh... He actually uses all of his tiles. Sorry, I read statement inattentively. deleted Edited by author 07.10.2013 22:24 # include <math.h> # include <stdio.h> # include <algorithm> using namespace std; int a,b,c,x,y; int main() { scanf("%d %d %d",&a,&b,&c);
for(int i=1;i<10001;i++) { x=0; y=0;
for(int j=1;j<=(int)sqrt((double)i)+1;j++) if(i%j==0) x++;
if(i-c>0) { for(int j=1;j<=(int)sqrt((double)(i-c))+1;j++) if(i%j==0) y++; }
if(b==x && a==y) {printf("%d",i);getchar();getchar();return 0;} }
printf("0");system("Pause"); } Why WA3? Maybe cause you forget about "no solution" or L > 10000 cases. I got AC after these checks. #include<stdio.h> int val(int n) { int i,count=0; if(n<=0) return n; else { for(i=1;i<=(int)sqrt(n);i++) { if(n%i==0) count++; } return count; } } int main() { int flag,m,n,k,i; flag=0; scanf("%d %d %d",&m,&n,&k); for(i=1;i<=10000;i++) { if(val(i)==n&&val(i-k)==m) { flag=1; break; } } if(flag==1) printf("%d",i); else printf("0"); //system("pause"); return 0; } I am Getting Wrong Answer For Test Case 1 Itself But i am getting the right answer 16 For The Input Cases Try the following test. It has helped me. 1 3 1 Right answer is 12 You just need to check all possible numbers of L (1..10000) to solve this. So you get O(n^2) solution. You just need to check all possible numbers of L (1..10000) to solve this. So you get O(n^2) solution. Maybe O( n^3/2 )? who can explain the problem? this problem is easy, A hint: If you have a square of 16 1*16 2*8 3..no, 3 no. 4*4... and that's all...just 3... Hope this help you! :) I understand now. Thank you very much! I also understand. Thank you. Thanks. Me understand too 8-) I see. Thanks! IC..THANKS My understands these good also. Tenk u for solveishn Yeah...it's a very clever hint Me too. Thx thank you very-very much! var a:array[1..10000]of integer; m,n,k,i,j:integer; begin fillchar(a,sizeof(a),0); readln(m,n,k); for i:=k+1 to 10000 do begin for j:=1 to trunc(sqrt(i)) do if i mod j=0 then a[i]:=a[i]+1; if (a[i]=n)and(a[i-k]=m) then begin writeln(i);halt;end; end; end. because your algorithm is wrong #include<stdio.h> #include<math.h> int yue(int n) { int p=1,i; for(i=2;i<=(int)sqrt(n);i++) if(n%i==0) p++; return p; } int main () { int m,n,k,i,test; while(scanf("%d %d %d",&m,&n,&k)!=EOF) { test=0; for(i=1;i<=1000;i++) if(n==yue(i)) { if(m==yue(i-k)) { printf("%d\n",i); test=1; break; } } if(test==0) printf("0\n");
} return 0; } [code deleted] Edited by moderator 28.05.2007 17:49 Delete your code. It not good for beginner ! If text were like this (You are given three numbers – M, N and K. You should find the less number L, such as you can form !!!EXACTLY!!! N different rectangles using all EXACTLY L tiles, and form M rectangles using L-K tiles.), I would solve this problem whithout so many submittions=) P.S. Yo shouldn't correct text, this is my whish =) Amount of rectangles is equal to the number of divisiors of tiles count wich are no more than Square_Root(tiles count). So the part of code solving this problem may be the following: For L:=1 To 10000-K Do Begin DivisiorsCount:=1; For J:=2 To Trunc(Sqrt(L)) Do If L Mod J=0 Then Inc(DivisiorsCount); If DivisiorsCount=M Then Begin DivisiorsCount2:=1; For J:=2 To Trunc(Sqrt(L+K)) Do If (L+K) Mod J=0 Then Inc(DivisiorsCount2); If DivisiorsCount2=N Then Begin SoulutionExists:=True; Break; End; End; End; You should output L+K if SolutionExists, 0 - otherwise. program windy; var n,i,m,k,j,n1,n2:longint; c:boolean; begin readln(m,n,k); c:=true; i:=k+1; while c and (i<=10000) do begin n1:=0; n2:=0; for j:=2 to trunc(sqrt(i)) do begin if i mod j=0 then n1:=n1+1; if (i-k) mod j=0 then n2:=n2+1; end; if (n1+1=n) and (n2+1=m) then c:=false else i:=i+1; end; if c then writeln(0); if not c then writeln(i) end. My program is here: var m,n,k:longint; min:longint; function nums(a:longint):longint; var i,tot:longint; begin tot:=0; for i:=1 to trunc(sqrt(a)) do if a mod i=0 then inc(tot); nums:=tot; end; begin readln(m,n,k); for min:=1 to 10000 do begin if (nums(min)=n)and(nums(min-k)=m) then begin writeln(min); exit; end; end; writeln(0); end. min should be not less than k or ur program'll get crash because it try to find square root of an negative integer :) #include <stdio.h> #include <math.h> int i,m,n,k; int num(int num) { int i,tot=0; for (i=1; i<=(int)sqrt(num); ++i) if (num%i==0) ++tot; return tot; } int main() { scanf("%d%d%d",&m,&n,&k); for (i=k; i<10000; ++i) if ((num(i)==n)&&(num(i-k)==m)) { printf("%d",i); exit(0); } printf("%d",0); return 0; } |
|