本帖最后由 michael_llh 于 2017-1-8 23:25 编辑
Count Divisors You have been given 33 integers l, r and k. Find how many numbers between l and r (both inclusive) are divisible by k. You do not need to print these numbers, you just have to find their count. Input Format
The first and only line of input contains 3 space separated integers l, r and k. Output Format
Print the required answer on a single line. Constraints
1≤l≤r≤10001≤l≤r≤1000
1≤k≤1000 SAMPLE INPUT
1 10 1 SAMPLE OUTPUT
10 题意分析: 其实这道题非常简单,就是给定三个数值,前两个是一个范围,这两个端点都是包含的,然后最后一个数字是一个除数,于是说在这两个数值之间有多少个被第三个数整除的,输出这个计数的值就可以了。
参考代码:
#include <iostream> using namespace std;
int main() { int l,r,k; cin >> l >> r >> k; int count = 0; for(int i=l; i<=r; i++){ if(i%k==0) count ++; } cout << count << endl; return 0; }
|