杨陈


私信TA

用户名:yccc

访问量:13246

签 名:

等  级
排  名 80
经  验 9230
参赛次数 0
文章发表 64
年  龄 0
在职情况 学生
学  校 湖北生物科技职业学院
专  业

  自我简介:

一开始想的是直接暴力破解 然后数量少一点还是可以但是数量多了就有点问题;

import java.util.Scanner;;
    public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int a=scanner.nextInt();
            int b=scanner.nextInt();
            int c=scanner.nextInt();
            int sum=0;
            for (int i = b; i <=c; i++) {
                boolean isFlag=false;
                for (int j = 2; j <= a; j++) {
                    if (i%j==0) {
                        if (isFlag==true) {
                            isFlag=false;
                        }else if(isFlag==false){
                            isFlag=true;
                        }
                    }
                }
                if (isFlag==true) {
                    sum++;
                }
            }
            System.out.println(sum);
    }
}

然后看了下写题解的大佬们写的 真的牛思路可以看第一个c++题解 我是水个题解

    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            long n = sc.nextLong();
            long l = sc.nextLong();
            long r = sc.nextLong();
            long a=r-l+1;
            long b=(long)Math.sqrt(r)-(long)Math.sqrt(l);
            System.out.println(a-b);
        }
    }


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

大佬的代码不会有问题吗,我用大佬的代码试了下,10 4 10 用例为什么会是6,不应该是5吗
2021-05-12 16:14:47
  • «
  • 1
  • »