快速幂:
代码:
快速幂
int result(int a,int b,int m)
{
int d=1,t=a;
while(b)
{
if(b&1)
d=(d*t)%m;
b/=2;
t=(t*t)%m;
}
return d;
}
A range is given, the begin and the end are both integers. You should sum the cube of all the integers in the range.
Each case of input is a pair of integer A,B(0 < A <= B <= 10000),representing the range A,B A,B.
2 1 3 2 5
Case #1: 36 Case #2: 224
题意:输入从A到B范围内数字的立方和。
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
long long int i,j,k,n,m,sum;
scanf("%lld",&i);
for(j=1;j<=i;j++)
{
scanf("%lld%lld",&n,&m);
for(sum=0;n<=m;n++)
{
sum=sum+n*n*n;
}
printf("Case #%lld: %lld\n",j,sum);
}
return 0;
}