about product in uint64
1 次查看(过去 30 天)
显示 更早的评论
My question is iven an integer x which contains d digits, find the value of n (n > 1) such that the last d digits of x^n is equal to x. If the last d digits will never equal x, return inf.
Example :
%x = 2; (therefore d = 1)
%2^2 = 4, 2^3 = 8, 2^4 = 16, 2^5 = 32
%n = 5;
So my solution is take x into uint64 vecto,then take the x^n by take product of a*x with example is
a=uint64([x])
for i=1:inf
a=a*x
for j=length(a):-1:1
b=rem(a(j)/10)
c=mod(a(j),10)
if a(j)>10
a(j)=c
a(j-1)=a(j-1)+b
end
end
if x==a(end-d:end)
break
end
end
%example : 0 0 0 2 *
2
==========
0 0 0 4 => [0 0 0 4]*2 =>[0 0 0 8]*2=>[0 0 0 16]=[0 0 1 6]*2=>[0 0 0 32]=[0 0 3 2] have a(end-d:end)==x then break
so my question is how could i product the number with over 2 digits in uint64()
1 个评论
Jan
2021-5-20
Why do you use uint64 instead of uint8 to store decimal digits?
What about limiting the solution to the UINT64 range, which is at least up to 1.8e19?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!