C语言:幂的末尾

题目描述

a^b的末3位数是多少?

输入输出格式

输入格式

两个正整数a,b。1≤a≤100,1≤b≤10000。
输出格式

从高位到低位输出幂的末三位数字,中间无分隔符。若幂本身不足三位,在前面补零。

完整代码

复制代码
#include <stdio.h>  
#include <stdlib.h>  
#include <string.h>  
#include <math.h>

int main() 
{  
    int a,b;
    scanf("%d%d",&a,&b);
    
    int i;
    int end=1;
    for(i=0;i<b;i++)
    {
		end=(end*a)%1000;
	}
	
	if(end==0)
	{
		printf("000");
	}else if(end<10)
	{
		printf("00%d",end);
	}else if(end<100)
	{
		printf("0%d",end);
	}else{
		printf("%d",end);
	}
    return 0;  
}
相关推荐
alphaTao4 小时前
LeetCode 每日一题 2026/8/24-2026/8/30
python·算法·leetcode
Interview Aid1125 小时前
TikTok OA 四题分享|半小时内 AC,题目基本都是实现题
java·开发语言·算法·面试·职场和发展
CoderIsArt12 小时前
C#中UI 线程与 Dispatcher
开发语言·ui·c#
顶点多余14 小时前
那些在算法中适合巩固的知识点---1
java·前端·算法
AI情绪识别开源15 小时前
检信 ALLEMOTION OS 加密打包可执行程序 — 全面测试报告版本: v1.3功能测试 / 性能测试 /
开发语言·数据结构·人工智能·功能测试
罗西的思考15 小时前
【Agentic RL / 强化学习框架】Molt 设计解读
人工智能·算法·机器学习
「QT(C++)开发工程师」16 小时前
C++ auto 用法详解
开发语言·c++
OPEN-F16 小时前
C++STL教程:容器适配器与实用工具
开发语言·c++
yaoxin52112316 小时前
507. Java 反射 - 在 BeanFactory 中实现依赖注入
java·开发语言