符合条件的整数 题解

符合条件的整数

https://ac.nowcoder.com/acm/contest/5902/A

从左边界往右找第一个%7=1的数x
从右边界往左找第一个%7=1的数y
然后用(y/x)+1即为里面符合条件的整数的个数

import java.math.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.*;
public class Main {
    public static void main(String args[])throws IOException
    {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        int a = (int)in.nval;
       in.nextToken();
        int b = (int)in.nval;
        if((long)(checkzuo((long)Math.pow(2,b)-1)-checkyou((long)Math.pow(2,a)))/7<0)
            out.println(0);
        else
            out.print(((long)(checkzuo((long)Math.pow(2,b)-1)-checkyou((long)Math.pow(2,a)))/7)+1);
        out.flush();
    }
    public static long checkzuo(long a)
    {
        long x = a;
        while(x%7!=1)
        {
            x--;
        }
        return x;
    }
    public static long checkyou(long a)
    {
        long x = a;
        while(x%7!=1)
        {
            x++;
        }
        return x;
    }
                  }
全部评论

相关推荐

不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务