[ZJ]a216: 數數愛明明
題目:
http://zerojudge.tw/ShowProblem?problemid=a216
-----------------------------------------------------------------------------------------------
#include<cstdio>
typedef long long int LL;
LL f (int n )
{
return n + n*(n-1) /2 ;
}
LL g (int n )
{
if (n==1 ){
return 1;
}
return f(n) + g(n-1) ;
}
int main(void)
{
LL n;
while(scanf("%d",&n)!=EOF)
{
printf("%lld %lld\n",f(n),g(n));
}
return 0;
}
http://zerojudge.tw/ShowProblem?problemid=a216
-----------------------------------------------------------------------------------------------
#include<cstdio>
typedef long long int LL;
LL f (int n )
{
return n + n*(n-1) /2 ;
}
LL g (int n )
{
if (n==1 ){
return 1;
}
return f(n) + g(n-1) ;
}
int main(void)
{
LL n;
while(scanf("%d",&n)!=EOF)
{
printf("%lld %lld\n",f(n),g(n));
}
return 0;
}
留言
張貼留言