luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/FH_04_13 #319

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Chi tiết bài tập - Luyện Code Online

https://luyencode.net/problem/FH_04_13

sonicquan6 commented 3 years ago

Dữ liệu ra: Các số nguyên tố nhỏ hơn n và thỏa mãn có tổng các chữ số chia hết cho 5.

Output lại có thêm số 6 tính là count. Nhưng khi làm bài thì khi có hoặc không có count vẫn bị WA ?

sonicquan6 commented 3 years ago

Code thử ở IDE khác thì bình thường ạ

Xem code AC

#include using namespace std; bool prime(int n){ if ( n < 2){ return false; } for ( int i = 2; i <= sqrt(n); i++){ if ( n % i == 0){ return false; } } return true; } bool chiahet( int n){ int sum = 0; if ( prime (n) == true){ while ( n > 0){ sum += n % 10; n /= 10; } } if ( sum % 5 == 0){ return true; } return false; } int main(){ int n, count = 0; cin >> n; for ( int i = 0; i < n; i++){ if( prime(i) == true && chiahet(i) == true){ cout << i << " "; count ++; } } return 0; }