首页 > 技术文章 > 51nod——2489 小b和灯泡(打表/平方数)

noobimp 2019-04-21 21:33 原文

这题打表去找因子的个数然后判奇偶也行。预处理O(n) 扫一遍判断O(n)。

for(int i = 1; i * i <= n; i++){
    for(int j = i; i * j <= n; j++){
        div[i * j] += 2;
        if(i == j) div[i * j]--;
    }
}

 

不过想深一步,这题就是找n以内的平方数的数量。so……

1 #include <bits/stdc++.h>
2 using namespace std;
3 int main(){
4     int n; cin>>n;
5     cout<<(int)sqrt(n)<<endl;
6     return 0;
7 }

 

推荐阅读