Project Euler #99: Largest exponential

Sort by

recency

|

27 Discussions

|

  • + 0 comments

    C++

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() 
    {    
        int N;
        cin >> N;
        
        vector<pair<long long, long long>> pairs;    
        
        for(int i=0; i<N; i++)
        {
            long long a, b;
            cin >> a >> b;            
    
            pairs.push_back({a, b});
        }
           
        int K;
        cin >> K;        
        
        sort(pairs.begin(), pairs.end(), [&](pair<long long, long long> a, pair<long long, long long> b)
         {
            return ((a.second * log(a.first)) < (b.second * log(b.first)));
         });
        
        cout << pairs[K-1].first << " " << pairs[K-1].second;
        return 0;
    }
    
  • + 0 comments

    Python

    from math import log
    v = []
    for _ in range(int(input())):
        a, b = map(int, input().split())
        v.append((b*log(a), a,b))
    k = int(input())
    x, a, b = sorted(v)[k-1]
    print (a, b)
    
  • + 0 comments

    Watch those overflows!

  • + 0 comments

    It looks that almost of all accepted solution fails one of these cases.

    Input

    2
    57592  651791025
    10000 775690333
    1
    

    Output

    57592  651791025
    

    Input

    2
    135366 5167045
    10 26514741
    1
    

    Output

    10 26514741
    
  • + 0 comments

    It is an easy problem not a medium