Sort by

recency

|

68 Discussions

|

  • + 0 comments

    include

    using namespace std; int main(){

    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
    cin>>a[i];
    }
    int count=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if((a[i]+a[j])%k==0){
                count++;
            }
        }
    }
    cout<<count<<endl;
    

    }

  • + 0 comments

    this is the solution in C int main() { int n,k; scanf("%d",&n); scanf("%d",&k); int a[n]; for(int i=0;i

  • + 0 comments

    can anyone explain which requirement is violating this code?

    if name == 'main':

    nk = input().split()

    n = int(nk[0])

    k = int(nk[1])

    a = list(map(int, input().rstrip().split())) if((n>=2 and n<=100) and ( k>=1 and k<=100) ): for i in range(len(a)): if (a[i]>=1 and a[i]<=100): pass

    print(len([[i,j]for i in a for j in a if (i

  • + 0 comments

    My solution in c# passed all the test cases using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution {

    static void Main(String[] args) {
        string[] tokens_n = Console.ReadLine().Split(' ');
        int n = Convert.ToInt32(tokens_n[0]);
        int k = Convert.ToInt32(tokens_n[1]);
        string[] a_temp = Console.ReadLine().Split(' ');
        int[] a = Array.ConvertAll(a_temp,Int32.Parse);
        int count=0;
        for(int i=0; i<n-1; i++)
        {           
            for(int j=i+1; j<n; j++)
            {
                if((a[i]+a[j])%k==0)
                {
                    count=count+1;
                }
            }
        }
        Console.WriteLine(count);
    
    }
    

    }

  • + 0 comments

    My solution in C,passed all test cases..

    int main()

    {

    int n; 
    
    int k;
    
    int count=0;
    
    scanf("%d %d",&n,&k);
    
    int a[100];
    
    for(int i = 0; i < n; i++)
    {
    
       scanf("%d",&a[i]);
    
    }
    for(int i=0;i<n;i++)
    
        {
    
        for(int j=i+1;j<n;j++)
    
            {
    
            if((a[i]+a[j])%k==0)
    
                count++;
    
        }
    }
    
    printf("%d",count);
    
    return 0;
    

    }