符合条件的整数 题解
符合条件的整数
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; } }