题解 | 小红的正整数构造
小红的正整数构造
https://www.nowcoder.com/practice/7aa37cbc28034fe5af562ec7e44d1e76
// 段姐姐开课啦。像这样想知道一群里面某一个到底有没有出现,用标记bool就可以啦
// 1. 输入 l,r 左右范围, x
// 2. 寻找 范围内,x的倍数,输出其中一个。
// 3.for循环,问每一个除以x是否为零,如果为零,输出i 否则输出-1;
#include <bits/stdc++.h>
using namespace std;
int main(){
int l,r,x;
cin >> l >> r >>x;
int m;
bool a = false;//这个代表目前没有找到
for(int i = r;i>=l;i--){
if(i%x==0){
m=i;
a = true;
}
}
if(a == true){
cout << m << endl;
}else{
cout << -1<< endl;
}
return 0;
}

