[Mảng 1 Chiều Cơ Bản]. Bài 16. Liệt kê

View as PDF

Submit solution

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

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

Cho mảng số nguyên A[] gồm N phần tử, hãy đếm số lượng các phần tử thỏa mãn các yêu cầu sau

  1. Số lượng số nguyên tố trong dãy
  2. Số lượng số thuận nghịch trong dãy
  3. Số lượng số chính phương trong dãy
  4. Số lượng số có tổng chữ số của nó là số nguyên tố.

Đầu vào

Dòng đầu tiên là số nguyên dương N

Dòng thứ 2 gồm N số nguyên viết cách nhau một vài khoảng trắng


Giới hạn

1<=N<=100

0<=A[i]<=10000


Đầu ra

In ra 4 dòng số lượng số tương ứng với 4 yêu cầu trên


Ví dụ :

Input 01
6
4 1682 5972 6331 9872 3956
Output 01
0
1
1
4

Comments

Please read the guidelines before commenting.



  • 3
    khanhhduy_1305  commented on Sept. 17, 2024, 2:31 a.m.

    include<bits/stdc++.h>

    using namespace std; int nguyento(int n) { if(n<2) return 0; for(int i=2;i<n;i++) if(n%i==0) return 0; return 1; } int tong(int n) { int s=0; while(n!=0) { s+=n%10; n/=10; } return s; } int thuannghich(int n) { int m = 0, tmp = n; while(n != 0){ m = m * 10 + n % 10; n /= 10; } if(tmp == m){ return 1; } return 0; } int main() { int nt=0,tn=0,cp=0,tong1=0; int n; cin>>n; int a[n+9]; for(int i=0;i<n;i++) { cin>>a[i]; if (nguyento(a[i])) ++nt; if (thuannghich(a[i])) ++tn; if (sqrt(a[i])==trunc(sqrt(a[i]))) ++cp; if(nguyento(tong(a[i]))) ++tong1; } cout<<nt<


  • 1
    NhatTien2912  commented on Aug. 14, 2024, 6:56 p.m.

    include <iostream>

    include <vector>

    include <cmath>

    include <iomanip>

    include <set>

    include <map>

    include <algorithm>

    bool cp(int n) { int x = sqrt(n); if (x * x == n) return 1; else return 0; } bool isprime(int n) { if (n < 2) return 0; for (int i = 2; i <=sqrt(n); i++) { if (n % i == 0) return 0; } return 1; } bool palin(int n) { int org = n; // loi thuong gap vi n da bi thay doi int x = 0; while (n) { int tmp = 0; tmp = n % 10; x = x * 10 + tmp; n /= 10; } if (x== org) return 1; else return 0; } bool sip(int n) {

    int sum = 0;
    while (n) {
        int tmp = 0; 
        tmp = n % 10;
        sum += tmp;
        n /= 10;
    }
    if (isprime(sum)) return 1;
    else return 0;
    

    } using namespace std;
    int main(){ int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0; int n; cin >> n; vector<int> a(n); for (int& x : a) cin >> x; for (int i = 0; i < n; i++) { if (isprime(a[i])) cnt1++; else if (palin(a[i])) cnt2++; else if (cp(a[i])) cnt3++; else if (sip(a[i])) cnt4++; } cout << cnt1 << endl; cout << cnt2 << endl; cout << cnt3 << endl; cout << cnt4 ; return 0; }

    sao bi wrong ans nhieu test case qua :<


  • -10
    hoangphuong  commented on May 17, 2024, 1:32 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.