UVA10790
题目中明明说:Each line in the input will contain two positive integers a ( 0 < a20000) and b ( 0 < b20000). 。。为什么a,ba要定义成long long int 呢?
#include<stdio.h>
int main()
{
int count=0;
long long int num,a,b;
while(1)
{
scanf("%lld%lld",&a,&b);
if(a==0&&b==0)
break;
count++;
num=(a-1)*a*b*(b-1)/4;
printf("Case %d: %lld\n",count,num);
}
return 0;
}
上面这段过了,但是下面那段就WA了呢?、
#include<stdio.h>
int main()
{
int count=0,a,b;
long long int num;
while(1)
{
scanf("%lld%lld",&a,&b);
if(a==0&&b==0)
break;
count++;
num=(a-1)*a*b*(b-1)/4;
printf("Case %d: %lld\n",count,num);
}
return 0;
}
UVA10790
[解决办法]
num=(a-1)*a*b*(b-1)/4
不定义成long long的话这个溢出。
[解决办法]