[Mảng 1 Chiều Cơ Bản]. Bài 46. Cặp số chia hết cho 28

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Java 4.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

28Tech là người rất thích số 28, anh ta cho bạn mảng A[] gồm N phần tử, bạn hãy đếm xem trong mảng có bao nhiêu cặp số A[i], A[j] với i khác j mà khi cộng với nhau sẽ tạo thành 1 số chia hết cho 28.


Đầu vào

Dòng 1 là N : số phần tử trong mảng

Dòng 2 là N phần tử cách nhau 1 khoảng trắng


Giới hạn

1<=N<=10^6

0<=A[i]<=10^9


Đầu ra

In ra số cặp thỏa mãn


Ví dụ :

Input 01
5
1 14 14 27 27
Output 01
3

Comments

Please read the guidelines before commenting.



  • -13
    binhngoan261009  commented on Sept. 1, 2024, 2:44 p.m.

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


  • -7
    nguyenanhquang  commented on Aug. 8, 2024, 7:50 a.m.

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


  • -5
    minhquan2905  commented on July 28, 2024, 11:57 a.m.

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


  • 6
    minhquan2905  commented on July 28, 2024, 10:59 a.m.

    vận dụng: A % 28 = 0 <=> (a%28 + b%28) % 28 = 0 => đặt x = a%28, y=b%28 <=> (x+y)%28 = 0 mà x, y <= 28 -> x+y=28 -> bài toán trở thành tìm, đếm cặp số dư bằng 28. (TH đặc biệt: x=y=14 , x=y=0 -> xét riêng)


    • -1
      GodNona  commented on Feb. 2, 2025, 4:34 p.m.

      A giúp e với a. E bị wrong answer

      include <bits/stdc++.h>

      using namespace std;

      define ll long long

      const int MOD = 1e9 + 7;

      ll a[1000006]; ll dem[28];

      int main() { iosbase::syncwith_stdio(0); cin.tie(NULL);

      int n; cin >> n;
      for(int i = 0; i < n; i++)
          cin >> a[i];
      
      for(int i = 0; i < n; i++)
          dem[a[i] % 28]++;
      
      int res = 0;
      res += dem[0] * (dem[0] - 1) / 2;
      for(int i = 1; i <= 13; i++)
          res += dem[i] * dem[28 - i];
      res += dem[14] * (dem[14] - 1) / 2;
      
      cout << res;
      
      return 0;
      

      }


      • 0
        minhquan2905  commented on Feb. 4, 2025, 4:37 p.m.

        biến res bị tràn, để ll đi =D


    • -1
      Long4200  commented on Jan. 28, 2025, 6:31 a.m.

      tks bro


  • -18
    NTH11112222  commented on May 25, 2024, 2:33 a.m.

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