3174 含K个3的数
#include<bits/stdc++.h> #define f(i,s,e) for(int i = s; i <= e; i++) #define ll long long using namespace std; const int N = 1e3+10,inf = 0x3f3f3f3f; int main() { int n,k,sum = 0; //sum用来统计n里有多少个3 cin >> n >> k; int f1 = 0,f2 = 0; //f1 = 1说明能被19整除,f2 = 1说明n里面刚好有k个3 if(n % 19 == 0) f1 = 1; //n能被19整除 while(n > 0) { if(n % 10 == 3) sum++; //3出现的次数 + 1 n /= 10; } if(sum == k) f2 = 1; //刚好有k个3 if(f1 == 1 && f2 == 1) //两个条件同时为真 cout << "YES"; else cout << "NO"; return 0; }