站外题求助

题目总版

Gcc_Gdb_7_8_1 @ 2024-11-16 16:05:12

https://www.luogu.com.cn/problem/U505175

juruo 的代码:

#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define Pii pair<int, int>
#define ULL unsigned long long

namespace gdb7
{
    bool goodnum[10000010], is_prime[10000010], cnt;
    int prime[1000010];

    int main() {
        int n;
        cin >> n;
        is_prime[0] = is_prime[1] = true;
        for (int i = 2; i <= n; ++i) {
            if (!is_prime[i]) {
//              cout << "    i" << i << endl;
                prime[++cnt] = i;
                for (LL j = 1; j <= n; ++j) {
                    goodnum[j] = true;
                }
            }
            for (int j = 1; j <= cnt && i * prime[j] <= n; ++j) {
                is_prime[i * prime[j]] = true;
                if (i % prime[j] == 0) {
                    break;
                }
            }
        }
        for (int i = 1; i <= n; ++i) {
            cout << "("<< is_prime[i] << ", " << goodnum[i] << "), ";
        }
        cout << "\ncnt:" << cnt << endl;
        for (int i = 1; i <= cnt; ++i) {
            cout << prime[i] << " ";
        }
        cout << endl;
        for (int i = n; i >= 1; --i) {
            if (goodnum[i]) {
                cout << i << endl;
                break;
            }
        } 
        return 0;
    }
};

int main()
{
    return gdb7::main();
}

by Gcc_Gdb_7_8_1 @ 2024-11-16 16:06:30

肯定 TLE


by TeaQiLang @ 2024-11-16 16:08:33

#include<bits/stdc++.h>
using namespace std;
bool qwq(int num){
    for (int i=2;i<=sqrt(num);++i){
        int temp=num;
        while(temp%i==0){
            temp/=i;
        }
        if(temp==1) return true;
    }
    return false;
}
int main() {
    int n;
    cin>>n;
    for(int i=n;i>= 1;--i){
        if(qwq(i)) {
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

by TeaQiLang @ 2024-11-16 16:09:07

@Gcc_Gdb_7_8_1


by hjb13357896690 @ 2024-11-16 16:09:47

重打换思路,不要惋惜O(∩_∩)O~(既然你是蒟蒻,那就服从大佬超级蒟蒻的命令吧)


by TeaQiLang @ 2024-11-16 16:10:34

@hjb13357896690 采菊东篱


by hjb13357896690 @ 2024-11-16 16:11:32

@Gcc_Gdb_7_8_1 问一下是哪个团里的


by TeaQiLang @ 2024-11-16 16:13:23

@hjb13357896690 都说了是站外题


by MLE_Automaton @ 2024-11-16 16:14:20

@Gcc_Gdb_7_8_1 看不懂你的代码,我的思路:枚举log n往下的数,二分得到n的i次根向下取整,再幂i,取最大,总时间复杂度是log^3 n


by Gcc_Gdb_7_8_1 @ 2024-11-16 16:14:20

@hjb13357896690 某内部 OJ


by Gcc_Gdb_7_8_1 @ 2024-11-16 16:15:21

哦,对了,其中有调试代码


| 下一页