[Làm Quen OJ]. Bài 33. Số chẵn có K chữ số

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Problem source:
28Tech
Problem type
Allowed languages
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Cho số nguyên dương N, bạn hãy kiểm tra N có phải là số chẵn có K chữ số hay không ? Nếu có hãy in ra true, ngược lại in ra false.

Các bạn có thể làm theo hướng dẫn này, trong đó ???????? sẽ là biểu thức để kiểm tra.

bool check = ????????;
cout << boolalpha << check << endl;

Đầu vào
  • Dòng duy nhất chứa NK

Giới hạn
  • 1 <= N <= 10^18

  • 1 <= K <= 18


Đầu ra
  • In ra true hoặc false

Ví dụ :

Input 01
2000 4
Output 01
true

Comments

Please read the guidelines before commenting.



  • 0
    pvt6_0023  commented on March 1, 2026, 3:28 a.m.

    include <bits/stdc++.h>

    using namespace std;

    int main() { iosbase::syncwith_stdio(false); cin.tie(NULL); string s;cin>>s; int k;cin>>k; (stoll(s)%2==0 and s.size()==k)?cout<<"true":cout<<"false"; return 0; }


  • 0
    TIEN_DAT_EPE_2006  commented on Feb. 27, 2026, 8:29 a.m.

    include <bits/stdc++.h>

    using namespace std; int main(){ long long n; cin >> n; int k; cin >> k; bool check = (n % 2 == 0) && (n >= pow(10,k-1)) && (n < pow(10,k)); cout << boolalpha << check << endl; return 0; }