取X的Y次方的末尾几位

来源:互联网 发布:手机屏幕破碎软件 编辑:程序博客网 时间:2024/05/05 03:42

知识点:
求后几位就对10的几次方取余
注意下面的输入格式应为:“13**13”,因为scanf(“%d** %d”,&x,&y);

//求1313次方的最后三位数#include <stdio.h>int main(){    int i,x,y,last=1;//变量last保存求xy次方过程中的部分乘积的后三位    printf("Input X and Y(X**Y):");    scanf("%d**%d",&x,&y);    for(i=1;i<=y;i++)//x自乘ylast=last*x%1000;//lastx后对1000取模,即求积的后三位    printf("The last 3 digits of %d**%d is:%d\n",x,y,last%1000);//打印结果    return 0;}
1 0