之前公开赛的题目『ZOI Round #1』奇妙数
我的代码:
//暴力20pts
#include <iostream>
#include <math.h>
using namespace std;
int gnt=0;
bool magic(int x){
for (int a=0;a<30;a++){
for (int b=0;b<19&&pow(2,a)*pow(3,b)<=x;b++){
for (int c=0;c<13&&pow(2,a)*pow(3,b)*pow(5,c)<=x;c++){
for (int d=0;d<11&&pow(2,a)*pow(3,b)*pow(5,c)*pow(7,d)<=x;d++){
gnt++;
if (pow(2,a)*pow(3,b)*pow(5,c)*pow(7,d)==x){
return 1;
}
}
}
}
}
return 0;
}
int main()
{
int l,r,cnt=0;
cin>>l>>r;
for (int i=l;i<=r;i++){
if (magic(i)){
cnt++;
}
}
cout<<cnt;
return 0;
}
请问有什么更好的方法判断「奇妙数」?
或者说有没有什么通项公式可以直接AC100pts?