Fermats theorem is not working in primality test

i am taking the number as string as constraint is given 2^63,
then i convert it into long long by mod 1000000007
then i pass the number to power function
with the a
1.random number<number obtained from string
2.number obtained from string
3.m i.e.1000000007
next i do ans%(number obtained from string)
But it is not resulting to 1 even for prime numbers