Direct access to element of STL "set"

Viewed 1608

How can I directly access a element of a STL set by index??

I got errors no match for 'operator+'

#include<bits/stdc++.h>
..
set < long  long > s;
set <long long > :: iterator it;
it = s.begin() + k;
       cout << (*it);

here k is the index of require element.

fore more specifically i want to solve a problem using set.

here is the problem link: k-th divisor

and this is my error code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    set<long long> s;
    set<long long >:: iterator it;
    long long i,n,k, ln;
    cin >> n>> k;
        ln = sqrt(n);
        for(i = 1; i <= ln; i++)
        {
            if(n%i == 0)
            {
                s.insert(i);
                s.insert(n/i);
            }
        }
        if(s.size() < k)
            printf("-1\n");
        else
        {
            it = s.begin() + k;
            cout << (*it);
        }

        s.clear();
    return 0;
}

help me out

3 Answers
Related