题目描述
小A同学有很多很多张爱思创积分卡,其中 1 分的有 n 张,剩下的均为 500 分的积分卡(可视为有无数张)。
现在小A同学想用手上的积分兑换一个需要花费 x 分的礼物,请问他是否能在不找零的情况下完成兑换,可以则输出
Yes
,不能则输出No
。输入格式
第一行:整数 x (1≤x≤10000)
第二行:整数 n (0≤n≤1000)
输出格式
一行一个字符串,为
Yes
或No
。样例输入
2022 0
样例输出
No
样例输入
2022 100
样例输出
Yes
问题提示
源代码
#include <bits/stdc++.h>
using namespace std;
int main(){
int x,n,m;
cin>>x>>n;
m=x-x%500;
if(n>=x){
cout<<"Yes";
return 0;
}
if(x%500>n){
cout<<"No";
return 0;
}
for(int i=0;i<=x%500;i++){
if(m+i==x){
cout<<"Yes";
return 0;
}
}
return 0;
}