这道题目细节琐碎,稍不注意就会WA ,特别是大数的范围,一开始没有把n声明为long long 导致最大的那个数 2147483647 结果为0 还有一开始用了 pow() 这个函数,也应该用double去接受结果。
#include#include #include #include #include #include #include #include #include #include using namespace std;int main(){ int cnt,t; long long n,sum,temp,m=0; while(cin>>n){ m++;sum=0,cnt=0; t=sqrt(n+1); if(n==0) break; printf("Case %d: ",m); if(n==1) {cout<<2< 1){ sum+=n; cnt++; } if(cnt==1) {printf("%lld\n",sum+1);} else if(cnt==0) printf("%lld\n",n+1); else printf("%lld\n",sum); } return 0;}