SHARE
TWEET

Untitled

a guest Oct 18th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define MOD 1000000007
  3.  
  4. using namespace std;
  5.  
  6. long long int powermod(long long int base, long long int power) {
  7.     if (power == 0) {
  8.         return 1;
  9.     }
  10.     else {
  11.         long long int cur = powermod(base, power / 2);
  12.         cur = cur * cur;
  13.         cur = cur % MOD;
  14.         if (power % 2 == 1)
  15.             cur = cur * base;
  16.         cur = cur % MOD;
  17.         return cur;
  18.     }
  19. }
  20.  
  21. int main()
  22. {
  23.     long long int n, x, maxi = -1000000007, premaxi = -1000000007, curr, prev;
  24.     cin >> n >> x;
  25.     n %= MOD;
  26.  
  27.  
  28.     premaxi = (x * powermod(5, 1)) % MOD;
  29.     maxi = premaxi * 5 % MOD;
  30.  
  31.     if(maxi < premaxi) {
  32.         swap(maxi, premaxi);
  33.     }
  34.  
  35.     prev = x * powermod(5, 2);
  36.  
  37.     for(int i = 3; i <= n; i++) {
  38.         curr = prev * 5 % MOD;
  39.         if(curr > maxi) {
  40.             swap(maxi, premaxi);
  41.             maxi = curr;
  42.         }
  43.         else {
  44.             if(curr > premaxi) {
  45.                 premaxi = curr;
  46.             }
  47.         }
  48.         prev = curr;
  49.     }
  50.  
  51.     cout << premaxi << " " << maxi;
  52.     return 0;
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top