noip 考试c++用pow(int,int)能不能过 程序如下
#include<iostream>#include<fstream>#include<cmath>usingnamespacestd;intmain(){freopen...
#include<iostream>
#include<fstream>
#include<cmath>
using namespace std;
int main()
{
freopen("coin.in","r",stdin);
freopen("coin.out","w",stdout);
int n,i,j,ans=0,x=0;
cin>>n;
while(n>x)
{
x++;
n-=x;
ans+=pow(x,2);
}
if(n!=0)
ans+=n*(x+1);
cout<<ans<<endl;
return 0;
} 展开
#include<fstream>
#include<cmath>
using namespace std;
int main()
{
freopen("coin.in","r",stdin);
freopen("coin.out","w",stdout);
int n,i,j,ans=0,x=0;
cin>>n;
while(n>x)
{
x++;
n-=x;
ans+=pow(x,2);
}
if(n!=0)
ans+=n*(x+1);
cout<<ans<<endl;
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询