Sort by

recency

|

69 Discussions

|

  • + 0 comments

    c=0 for i in range(len(a)): for j in range(i+1,len(a)): if (a[i]+a[j])%k==0: c+=1 print(c)

  • + 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);
    
    }
    

    }