// PowerSequence.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <math.h>
int main(int argc, char* argv[])
{
int x=1,y=0;
double nums[5000],powerx,powery;
nums[1]=1;
int count=1;
int n;
printf("Input n:\n");
scanf("%d",&n);getchar();
powerx=pow(2,x);
while(count<n)
{
y++;
powery=pow(3,y);
while( powerx<powery)
{
nums[++count]=powerx;
if(count>=n)
goto end;
x++;
powerx=pow(2,x);
}
nums[++count]=powery;
}
end:
printf("%d:%.0lf\n",n,nums[n]);
double sum=0;
for(int i=1;i<=n;i++)
sum+=nums[i];
printf("sum:%.0lf\n",sum);
return 0;
}
3.3双幂序列
最新推荐文章于 2021-01-29 10:30:56 发布