Tokyo! Even though the trip was very rushed, it seemed to be enough for me. Even if I had extra time, I'd probably just roam around, see a few more landmarks and buildings, and enjoy more of the renowned local delicacies. Perhaps for every traveler, every city has its own advantages to admire.
https://leetcode.com/problems/minimum-replacements-to-sort-the-array/description/
https://leetcode.com/problems/minimum-replacements-to-sort-the-array/submissions/1035547342/
class Solution { public: long long minimumReplacement(vector<int>& nums) { long long ans = 0; int Max = nums.back(); for(int i = nums.size() - 2; i >= 0; --i) { //cout << i << " max = " << Max << " num = " << nums[i] << endl; if(nums[i] <= Max) { Max = nums[i]; continue; } int divisor = nums[i]; int dividend = Max; int mod = divisor % dividend; int quotient = divisor / dividend; if(mod == 0) { ans += quotient - 1; continue; } ans += quotient; // binary search to find max Max int l = mod, r = Max; while(l <= r) { int mid = (l + r) >> 1; int gap = mid - mod; int times = gap / quotient; if(gap % quotient !
cstdlib div div_t div(int numer, int denom); ldiv_t div(long int numer, long int denom); lldiv_t div (long long int numer, long long int denom); Returns the integral quotient and remainder of the division of numer by denom ( numer/denom ) as a structure of type div_t, ldiv_t or lldiv_t, which has two members: quot and rem.
Only int version for c
/* div example */ #include <stdio.h> /* printf */ #include <stdlib.