BUPT机试计院2017 Problem A

这种题就算做是打卡题了吧……能够写的更简单但是好像这样数据大会比较快,是的
原题:
Problem A
我记得是:
第一行是测试数据组数
接下来,给一个数,从1到这个数中,有几个数,既可以开二次方根,也可以开三次方根,输出这种数的个数。(好像是这样吧)
输入
2
1
64
输出
1
2

#include<iostream>
using namespace std;
const int maxn=100000;
bool sqrt2(int x){//开二次根
	if(x==1) return true;
	for(int i=1;i*i<=x;i++){
		if(i*i==x) return true;
	}return false;
} 
bool sqrt3(int x){//三次根
	if(x==1) return true;
	for(int i=1;i*i*i<=x;i++){
		if(i*i*i==x) return true;
	}return false;
} 
bool hash[maxn]={false};
void table(){//可以的数字为true
	for(int i=1;i<maxn;i++){
		if(sqrt2(i)&&sqrt3(i)) hash[i]=true;
	}
}
int main(){
	table();
	int n;
	cin>>n;
	while(n--){
		int x,num=0;
		cin>>x;
		for(int i=1;i<=x;i++){
			if(hash[i]) num++;//直接查询
		}cout<<num<<endl;
	}
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/qq_32719923/article/details/88755890