Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Sachin and his girlfriend editorial

$
0
0

Pre - requisite:

STL (C++)

Difficulty :

Easy

Problem statement:

We need to print the modulo 1007 of those numbers whose remainder value have not yet appeared.

Explanation:

we can use a map<long long int, long long int> m where the first index specifies the remainder value. Initially the value of m[i] for all i is 0 by default. Whenever we encounter a number we check if m[n%1007] is equal to 0 or not. If it is zero print the value and increment m[n%1007].

Solution:

#include<bits stdc++.h="">
using namespace std;
main()
{
    long long int t,a,r;
    map<long long="" int,long="" long="" int=""> m;
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld",&a);
        r=a%1007;
        if(m[r]==0)
        {
            printf("%lld\n",r);
            m[r]++;
        }
    }
return 0;
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>