1 条题解

  • 0
    @ 2026-7-11 16:42:56

    题目传送门

    先看这道题:

    l=2,r=11

    所以i为2,3,4,5,6,7,8,9,10,11

    筛选出它们的质因数

    部分代码如下,这是质因数包含2的:

      while(x%2==0){
          x/=2
      }
    

    这是质因数包含5的:

      while(x%5==0){
          x/=5
      }
    

    结果大概是这样:

    2=22=2

    3=33=3

    4=224=2*2

    5=55=5

    6=236=2*3

    7=77=7

    8=2228=2*2*2

    9=339=3*3

    10=2510=2*5

    11=1111=11

    然后一个个选再看那个x=1,ans就加加

    Code:

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int l,r;
        cin>>l>>r;
        int ans=0;
        for(int i=l;i<=r;i++){
            int x=i;
            while(x%2==0){
                x/=2;
            }
            while(x%5==0){
                x/=5;
            }
            if(x==1){
    			ans++;
    		}
        }
        cout<<ans<<endl;
    }
    

    信息

    ID
    1069
    时间
    1000ms
    内存
    256MiB
    难度
    普及−
    标签
    递交数
    4
    已通过
    2
    上传者