#pragma GCC optimize(fast)
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
long long x,n;
long long total=1;
scanf("%d%d", &x,&n);
for(int i=1;i<=n;i++)
{
total*=x;
}
int a=total%1000;
if(total<1000)
{
printf("%d",&total);
}
else
{
if(total%1000==0)
{
printf("000");
}
else if(a<10)
{
printf("00");
printf("%d",&a); }
else if(a<100)
{
printf("0");
printf("%d",&a);
}
else
{
printf("%d",&a);
}
}
}
不知道是不是我理解题目没到位,我的这个代码只能当第一个人报数2时算到前七位人报的数,后面的算不下去,太大了,希望多少给你点思路
有答案了也给我看一下,我也没学多久这玩意
int main()
{
int n;//你所在位置,1-10000
long long x;//初始为第一个人报的数,0-999,然后作为每个人报的数,考虑到可能数据旁大,故用longlong
int g, s, b;//大于三位数时的后三位
printf("请输入所在位置(1-10000)和第一个报数的数字(0-999):\n");
scanf("%d%lld", &n,&x);
if (n == 1)//你在第一位
{
printf("要报的数是:%lld\n", x);
return 0;
}
if (x == 1)//如果第一个人报1,1的1倍的后三位还是1
{
printf("要报的数是:%lld\n", x);
return 0;
}
if (x == 0)//如果第一个人报0,0的0倍的后三为位还是0
{
printf("要报的数是:%lld\n", x);
return 0;
}
if(x > 1 && n > 1)//排除上面的情况
{
for (int i = 0; i < n - 1; i++)//循环赋值,循环次数你的位置-1次
{
x = x * x;
}
printf("%lld\n", x);//可以打印看下结果
if (x <= 999)//如果最终结果小于等于三位数,那么直接输出
{
printf("要报的数是:%lld\n", x);
}
else//大于三位数的话,就求出最后三位数
{ g = x % 10;//个位数
s = x % 100 / 10;//十位数
b = x / 100 % 10;//百位数
printf("要报的数是:%d%d%d\n", b, s, g);
}
}
return 0;
}
```c
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
scanf("%d%d", &n,&k);
long long total=1;
for(int i=1;i<=k;i++)
{
total*=n;
}
if(total<1000)cout<<total<<endl;
else printf("%03d\n",total%1000);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
scanf("%d%d", &n,&k);
long long total=1;
for(int i=1;i<=k;i++)
{
total*=n;
}
if(total<1000)cout<<total;
else printf("%03d\n",total%1000);
return 0;
}