fork(1) download
  1. const fi='';
  2. fo='';
  3. maxn=100;
  4. base=1000000000;
  5. type arra=array[1..maxn,1..maxn] of integer;
  6. arrl=array[1..maxn,1..maxn] of longint;
  7. var a:arra;
  8. i,j,m,n:byte;
  9. l:arrl;
  10. f:text;
  11. res:int64;
  12. procedure nhap;
  13. begin
  14. assign(f,fi);
  15. reset(f);
  16. readln(f,m,n);
  17. for i:=1 to m do
  18. for j:=1 to n do read(f,a[i,j]);
  19. close(f);
  20. end;
  21. procedure init;
  22. begin
  23. for i:=1 to m do l[i,1]:=1;
  24.  
  25. res:=0;
  26. end;
  27. function kt(x,y:longint):boolean;
  28. var tmp:longint;
  29. begin
  30. while y>0 do
  31. begin
  32. x:=x mod y;
  33. tmp:=x;
  34. x:=y;
  35. y:=tmp;
  36. end;
  37. if x=1 then exit(false) else exit(true);
  38. end;
  39. procedure xuly;
  40. var ii,jj:byte;
  41. begin
  42. for i:=1 to m do
  43. for j:=1 to n-1 do
  44. begin
  45. for ii:=i-1 downto 1 do
  46. for jj:=j downto 1 do
  47. if kt(a[i,j],a[ii,jj]) then l[i,j]:=(l[i,j]+l[ii,jj]) mod base;
  48. for jj:=j-1 downto 1 do
  49. if kt(a[i,j],a[i,jj]) then l[i,j]:=(l[i,j]+l[i,jj]) mod base;
  50. end;
  51.  
  52. for i:=1 to m do
  53. for ii:=i downto 1 do
  54. for jj:=n-1 downto 1 do
  55. if kt(a[i,n],a[ii,jj]) then res:=(res+l[ii,jj]) mod base;
  56. end;
  57. procedure xuat;
  58. begin
  59. assign(f,fo);
  60. rewrite(f);
  61. writeln(f,res);
  62. close(f);
  63. end;
  64. begin
  65. nhap;
  66. init;
  67. xuly;
  68. xuat;
  69. end.
Success #stdin #stdout 0s 396KB
stdin
Standard input is empty
stdout
0