安装Lua最小开发运行环境:
apt-get install lua5.1-0-dev
find / -name lua.h
/home/hanxiaohua/work1/MathTool/lua/lua.h
/usr/include/lua5.1/lua.h
./luatest
./luatest: /usr/lib/x86_64-linux-gnu/liblua5.1.so.0: no version information available (required by ./luatest)
root@ubuntu:/home/cpptest/lua# ./luatest NumberTheory.lua
5!=120
6!=720
7!=5040
8!=40320
9!=362880
10!=3628800
11!=39916800
12!=479001600
4 -4 -4
4 6
totient(37)=36
totient(57)=36
totient(63)=36
totient(74)=36
totient(76)=36
100
7
PowerMod(5,-2,17)=15
PowerMod(5,-1,17)=7
PowerMod(5,0,17)=1
PowerMod(5,1,17)=5
PowerMod(5,2,17)=8
PowerMod(5,4,17)=13
PowerMod(5,8,17)=16
PowerMod(5,16,17)=1
在前30个正整数中,1,8,12,15,16,20,21,24,28,30,没有原根
lprimroot(2)=1,lprimroot(3)=2,lprimroot(4)=3,lprimroot(5)=2,lprimroot(6)=5,lprimroot(7)=3,lprimroot(9)=2,lprimroot(10)=3,lprimroot(11)=2,lprimroot(13)=2,lprimroot(14)=3,lprimroot(17)=3,lprimroot(18)=5,lprimroot(19)=2,lprimroot(22)=7,lprimroot(23)=5,lprimroot(25)=2,lprimroot(26)=7,lprimroot(27)=2,lprimroot(29)=2,有原根
function Factorial(n)
if n==0 or n==1 then
return 1
else
return n * Factorial(n-1)
end
end
--print("Enter a number : ")
--i = io.read("*number")
for i=5,12,1 do
io.write(i,"!=",Factorial(i),"\n")
end
--求2个整数的最大公约数
function GcdInt(a,b)
if(a*b<0) then
return -GcdInt(math.abs(a),math.abs(b))
end
if(a<b) then
local temp=a
a=b
b=temp
end
if(a%b==0)then
return b
else
return GcdInt(a%b,b)
end
end
local ret=GcdInt(12,32)
local ret1=GcdInt(-12,32)
local ret2=GcdInt(12,-32)
print(ret,ret1,ret2)
function Iscoprime(a,b)
local ret=0
if(GcdInt(a,b)==1)then
ret=1
end
return ret
end
--φ(n)表示不大于n且与n互素的正整数个数、n阶循环群中n阶元的个数、本原n次单位根(n次单位原根)的个数、整数模n乘法群(模n既约剩余类)(Z/p^nZ)^×中与n互素剩余类的个数
function Phi(n)
local ret=0
if(n==1)then
return 1
end
for i=1,n-1,1 do
ret=ret+Iscoprime(n,i)
end
return ret
end
--T(n)表示n的正因子的个数、n阶循环群子群的个数、Z/nZ理想的个数
function Sigma0(n)
local ret=0
for d=1,n,1 do
if(n%d==0)then
ret=ret+1
end
end
return ret
end
--totient(12)=4
--|S(C_