// PowerMultiSequence.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<math.h>
void swap(double& a,double& b)
{
if(&a==&b)
return;
double tmp=a;
a=b;
b=tmp;
}
int main(int argc, char* argv[])
{
printf("Input n:\n");
int n;
scanf("%d",&n);
getchar();
//double xH=log(n)/log(2);
//double yH=log(n)/log(3);
int count=0;
double nums[5000];
double value;
/*
for(int x=0;x<=xH;x++)
for(int y=0;y<=yH;y++)
if( (value=pow(2,x)*pow(3,y)) <= n)
{
count++;
nums[count]=value;
}
*/
double pow2x=1;
double pow3y=1;
for(pow2x=1;pow2x<=n;pow2x*=2)
for(pow3y=1;pow3y<=n;pow3y*=3)
if( (value=pow2x*pow3y) <= n)
{
count++;
nums[count]=value;
}
//下面进行排序
int lowerIndex;
for(int j,int i=1;i<count;i++)
{
lowerIndex=i;
for(j=i+1;j<=count;j++)
if(nums[lowerIndex]>nums[j])
{
lowerIndex=j;
}
swap(nums[lowerIndex],nums[i]);
}
printf("幂序列中小于%d的项数:%d\n",n,count);
printf("Input m:");
int m;
scanf("%d",&m);
getchar();
if(m<=count)
printf("从小到大第:%d项:%.0lf\n",m,nums[m]);
else
printf("所输入的m大于序列的项数\n");
return 0;
}