倍数|计蒜客2019蓝桥杯省赛 B 组模拟赛(一)

思路:从l枚举到r肯定超时,这时我们要转变思路!题目让我们求一个区间内的d的倍数,只需要求出r/d - l/d就是区间内d倍数的个数。

代码:

#include <iostream>
using namespace std;

long long r = 12302135942453;
int l = 1032;
int d = 234;

int main(){
	cout<<r/d - 1032/234<<endl; //左右区间都是闭合的 
	return 0;
}
原文地址:https://www.cnblogs.com/fisherss/p/10345199.html