求助
  • 板块学术版
  • 楼主Supa7onyz
  • 当前回复19
  • 已保存回复19
  • 发布时间2024/3/14 13:33
  • 上次更新2024/3/14 18:01:14
查看原帖
求助
1095806
Supa7onyz楼主2024/3/14 13:33

之前公开赛的题目『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?

2024/3/14 13:33
加载中...