3 solutions

  • 0
    @ 2024-9-27 20:56:49
    #include<stdio.h>
    #include<math.h>
    int a[10];
    int main()
    {
    	int n;
    	scanf("%d",&n);
    	while(n--)
    	{
    		int u;
    		scanf("%d",&u);
    		u = u%8;
    		a[u]++;
    	}
    	long long sum = 0;
    	if(a[4] >=2)
    	{
    		long pp  = 0;
    	for(int i = a[4]-1;i >= 1;i--)
    	{
    		pp+=i;
    	}
    	sum += pp;
    	}
    	
    	if(a[0] >= 2)
    	{
    		long oo = 0;
    	  for(int i = a[0]-1;i >= 1;i--)
    	   {
    		oo+=i;
    	   }
    	   sum += oo;
    	}
    	
    	
    	for(int i = 1;i < 4;i++)
    	{
    		long long d = a[i]*a[8-i];
    		
    		sum = sum + d;
    	}
    	printf("%lld",sum);
    	return 0;
    }
    
    
    • 0
      @ 2024-4-10 17:30:05
      #include <iostream>
      using namespace std;
      
      int64_t Add(int num)
      {
         int64_t sum = 0;
         for (int i = 0; i < num; i++)
             sum += i;
         
         return sum;
      }
      
      int main()
      {
         int n;
         cin >> n;
         int num;
         int A = 0, B = 0, C = 0, D = 0,
               E = 0, F = 0, G = 0, H = 0;
         int64_t  count = 0;
      
         for (int i = 0; i < n; i++)
         {
      	cin >> num;
      	switch (num % 8)
      	{
      		case 1:A++; break;
      		case 2:B++; break;
      		case 3:C++; break;
      		case 4:D++; break;
      		case 5:E++; break;
      		case 6:F++; break;
      		case 7:G++; break;
      		case 0:H++; break;
              }
         }
         count = A * G + B * F + C * E 
                      + Add(D)+Add(H);
      
         cout << count;
      
         return 0;
      }
      
      • 0
        @ 2024-3-30 20:49:33
        #include <iostream>
        #define int long long
        #define endl '\n'
        #define QAQ ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
        using namespace std;
        const int N=1e5+5;
        int a[N]={0},b[20]={0};
        signed main()
        {
            QAQ;
            int n,ans=0;
            cin>>n;
            for(int i=1;i<=n;i++)
            {
                cin>>a[i];
                b[a[i]%8]++;
            }
            for(int i=1;i<=n;i++)
            {
                if(a[i]%8!=4&&a[i]%8!=0)
                    ans+=b[8-a[i]%8];
                else
                    ans+=b[a[i]%8]-1;
                b[a[i]%8]--;
            }
            cout<<ans;
            
            return 0;
        }
        
        • 1

        Information

        ID
        6977
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        9
        Tags
        (None)
        # Submissions
        225
        Accepted
        12
        Uploaded By