跳到正文

题解

题解:P14663 [KenOI 2025] 倍数题

blue_ice_cube约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月21日
更新
2025年12月21日
篇幅
约 2 分钟
题目
P14663

版本

  1. v1当前

第一篇题解,希望通过!

题目传送门 | AC记录

这道题目我们首先列举出思路:

注意:TT组数据

一共要实现TT组,用for循环就好了(注意T≤1018T \leq 10^{18},比较大,容易TLE)

做法一(会TLE哦)

这里的思路是枚举+判断+计数,直接贴上错误code:

C++
#include<iostream>
#include<cmath>
signed main(){
    int t;
    std::cin >> t;
    for(int i = 0; i < t; i++){
        int n, cnt = 0;
        std::cin >> n;
        for(int j = 1; j <= (int)sqrt(n); j++){
            if(j % 3 == 0){
                cnt++;
            }
        }
        std::cout << cnt << std::endl;
    }
}

可惜的是,这段代码会TLE,只能得20分。时间复杂度:O(Tsqrt(n))O(Tsqrt(n))

所以,有没有通项?

=sqrt(n)/3sqrt(n) / 3不就行了? 这里附上AC code:

C++
#include<iostream>
#include<cmath>
signed main(){
    int t;
    std::cin >> t;
    for(int i = 0; i < t; i++){
        long long n, cnt = 0;
        std::cin >> n;
        std::cout << (int)sqrt(n) / 3 << std::endl;
    }
}

时间复杂度:O(T),ACO(T), \green{AC}!

原文