| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
很奇怪的事情,我用__int64是错的,int是对的我的程序用int时在处理大数的时候是来回溢得到正确答案,不过为什么int64不行,是不是测试数据给了负数啊...我试了半天,两个答案就是不一样(后面是我的代码,应该很简单,请知道问题的人赐教啊...ORZ...)
#include<stdio.h>
int x;
int t;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&x);
int c=0;
while(!(x&1))
{
c++;
x>>=1;
}
int a = x-1,b=x+1;
__int64 e=x-1,d=x+1;
if(a!=e||b!=d)while(1);//这里没有死循环
a<<=c;
b<<=c;
/* e<<=(__int64)c;
d<<=(__int64)c;*/
while(c--)
{
e=e*2;
d=d*2;
} //原来以为是<<问题,改成这个还是不幸
a++;
b--;
e++;
d--;
if(a!=e||b!=d)while(1);//这里+了就TLE,明显两个处理的结果是不一样的,是编译器问题还是给了负数
printf("%d %d\n",a,b);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator