fork download
  1. imports System
  2. imports System.Runtime.InteropServices
  3.  
  4. module CodeIQ2549
  5. const bufsiz as integer=32
  6.  
  7. 'MacPorts
  8. 'const libgmp as string="/opt/local/lib/libgmp.dylib"
  9. 'ideone
  10. const libgmp as string="/usr/lib/i386-linux-gnu/libgmp.so.10"
  11. 'const libgmp as string="/usr/lib/libgmp.so.3"
  12. 'paiza.io/atcoder
  13. 'const libgmp as string="/usr/lib/x86_64-linux-gnu/libgmp.so.10"
  14. 'wandbox/yukicoder
  15. 'const libgmp as string="/usr/lib64/libgmp.so.10"
  16. 'AOJ
  17. 'const libgmp as string="/usr/lib64/libgmp.so.3"
  18.  
  19. <DllImport("msvcrt",CallingConvention:=CallingConvention.Cdecl)>shared function write(x as integer,y as string,z as integer) as integer
  20. end function
  21. <DllImport("msvcrt",CallingConvention:=CallingConvention.Cdecl)>shared function fopen(x as string,y as string) as IntPtr
  22. end function
  23. <DllImport("msvcrt",CallingConvention:=CallingConvention.Cdecl)>shared function fflush(x as IntPtr) as integer
  24. end function
  25. <DllImport("msvcrt",CallingConvention:=CallingConvention.Cdecl)>shared function puts(x as string) as integer
  26. end function
  27. <DllImport("msvcrt",CallingConvention:=CallingConvention.Cdecl)>shared function system(x as string) as integer
  28. end function
  29.  
  30. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_init(a as IntPtr)
  31. end sub
  32. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_clear(a as IntPtr)
  33. end sub
  34. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_out_str(a as IntPtr,b as integer,c as IntPtr)
  35. end sub
  36. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_set(a as IntPtr,b as IntPtr)
  37. end sub
  38. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_set_str(a as IntPtr,b as string,c as integer)
  39. end sub
  40. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_set_si(a as IntPtr,b as long)
  41. end sub
  42. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared function __gmpz_cmp_si(a as IntPtr,b as long) as integer
  43. end function
  44. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared function __gmpz_get_si(a as IntPtr) as long
  45. end function
  46. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_abs(a as IntPtr,b as IntPtr)
  47. end sub
  48. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_add(a as IntPtr,b as IntPtr,c as IntPtr)
  49. end sub
  50. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_add_ui(a as IntPtr,b as IntPtr,c as long)
  51. end sub
  52. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_mul(a as IntPtr,b as IntPtr,c as IntPtr)
  53. end sub
  54. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_mul_si(a as IntPtr,b as IntPtr,c as long)
  55. end sub
  56. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_mul_ui(a as IntPtr,b as IntPtr,c as long)
  57. end sub
  58. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_sub(a as IntPtr,b as IntPtr,c as IntPtr)
  59. end sub
  60. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_sub_ui(a as IntPtr,b as IntPtr,c as long)
  61. end sub
  62. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_ui_sub(a as IntPtr,b as long,c as IntPtr)
  63. end sub
  64. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_tdiv_q(a as IntPtr,b as IntPtr,c as IntPtr)
  65. end sub
  66. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_tdiv_r(a as IntPtr,b as IntPtr,c as IntPtr)
  67. end sub
  68. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_tdiv_q_ui(a as IntPtr,b as IntPtr,c as long)
  69. end sub
  70. <DllImport(libgmp,CallingConvention:=CallingConvention.Cdecl)>shared sub __gmpz_tdiv_r_ui(a as IntPtr,b as IntPtr,c as long)
  71. end sub
  72.  
  73. sub mul(a1 as IntPtr,b1 as IntPtr,c1 as IntPtr,d1 as IntPtr,a2 as IntPtr,b2 as IntPtr,c2 as IntPtr,d2 as IntPtr)
  74. dim a0 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(a0)
  75. dim b0 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(b0)
  76. dim c0 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(c0)
  77. dim d0 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(d0)
  78. dim t as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(t)
  79. dim u as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(u)
  80.  
  81. __gmpz_mul(t,a1,a2)
  82. __gmpz_mul(u,b1,c2)
  83. __gmpz_add(a0,t,u)
  84. __gmpz_mul(t,a1,b2)
  85. __gmpz_mul(u,b1,d2)
  86. __gmpz_add(b0,t,u)
  87. __gmpz_mul(t,c1,a2)
  88. __gmpz_mul(u,d1,c2)
  89. __gmpz_add(c0,t,u)
  90. __gmpz_mul(t,c1,b2)
  91. __gmpz_mul(u,d1,d2)
  92. __gmpz_add(d0,t,u)
  93.  
  94. __gmpz_set(a1,a0)
  95. __gmpz_set(b1,b0)
  96. __gmpz_set(c1,c0)
  97. __gmpz_set(d1,d0)
  98.  
  99. __gmpz_clear(a0):Marshal.FreeHGlobal(a0)
  100. __gmpz_clear(b0):Marshal.FreeHGlobal(b0)
  101. __gmpz_clear(c0):Marshal.FreeHGlobal(c0)
  102. __gmpz_clear(d0):Marshal.FreeHGlobal(d0)
  103. __gmpz_clear(t):Marshal.FreeHGlobal(t)
  104. __gmpz_clear(u):Marshal.FreeHGlobal(u)
  105. end sub
  106.  
  107. sub Main()
  108. dim stdout as IntPtr=fopen("/dev/stdout","w")
  109.  
  110. dim a1 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(a1)
  111. dim b1 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(b1)
  112. dim c1 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(c1)
  113. dim d1 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(d1)
  114. dim a2 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(a2)
  115. dim b2 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(b2)
  116. dim c2 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(c2)
  117. dim d2 as IntPtr=Marshal.AllocHGlobal(bufsiz):__gmpz_init(d2)
  118.  
  119. __gmpz_set_si(a1,1)
  120. __gmpz_set_si(b1,0)
  121. __gmpz_set_si(c1,0)
  122. __gmpz_set_si(d1,1)
  123. __gmpz_set_si(a2,1)
  124. __gmpz_set_si(b2,1)
  125. __gmpz_set_si(c2,1)
  126. __gmpz_set_si(d2,0)
  127.  
  128. dim N as integer=int(Console.ReadLine())
  129. N=((N+3)\2)*2
  130. while N>0
  131. if (N mod 2)>0
  132. mul(a1,b1,c1,d1,a2,b2,c2,d2)
  133. end if
  134. mul(a2,b2,c2,d2,a2,b2,c2,d2)
  135. N\=2
  136. end while
  137. __gmpz_sub_ui(c1,c1,1)
  138. __gmpz_out_str(stdout,10,c1)
  139. fflush(stdout)
  140. puts("")
  141. fflush(stdout)
  142.  
  143. __gmpz_clear(a1):Marshal.FreeHGlobal(a1)
  144. __gmpz_clear(b1):Marshal.FreeHGlobal(b1)
  145. __gmpz_clear(c1):Marshal.FreeHGlobal(c1)
  146. __gmpz_clear(d1):Marshal.FreeHGlobal(d1)
  147. __gmpz_clear(a2):Marshal.FreeHGlobal(a2)
  148. __gmpz_clear(b2):Marshal.FreeHGlobal(b2)
  149. __gmpz_clear(c2):Marshal.FreeHGlobal(c2)
  150. __gmpz_clear(d2):Marshal.FreeHGlobal(d2)
  151. end sub
  152. end module
Success #stdin #stdout 0.04s 24936KB
stdin
2015
stdout
24410294683171395267259945469996127000411199333760853190535535281681195871429510314079442068798555059453792431772087225245168879580469159794544170936403149540819320510882801573596907938222922817134288725100817648047405608500267748766714030468003650259685406411646787207097050545802045736020993909154298598218721111963426993884619351338577630868510716463423585020972878819198991971234596733617320373133963970742975210614208