带入一个比较大的数就不对了,比如17的10次方就不对了,但小一点却是对的,这是为啥呢?

输入一个数的n次方,输入后三位
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{ unsigned long a,c, b,n,m=0;
unsigned long s;
scanf("%ld %ld",&a,&n);
s=a ;
if (n==0)
{

printf("The last 3 numbers is 1.\n");
return 0;
}
if (n==1)
{
    printf("The last 3 numbers is %ld.\n",a);
    return 0;
}
if (n>1)

do
{
s=s*a;
m=m+1;
}
while(m<n-1);
b=s;
if (b<1000)
{
c=b;
}
else
{
c=b%1000;
}
printf("The last 3 numbers is %ld.",c);

}
(才学计算机,求大佬们教教,谢谢😊)

额,如果是a赋值为17^10,那么s也是17^10,你后面循环体又有个s=s*a,那么相乘后的s就超unginal long的范围了。(相乘后s有25位,unsigned long范围为20位)🧐