GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add 668_Kth_Smallest_Number_in_Multiplication_Table (#21) · manondidi/leetcode@f8a6d76

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • cpp
    • 668_Kth_Smallest_Number_in_Multiplication_Table.cpp
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cpp/668_Kth_Smallest_Number_in_Multiplication_Table.cpp‎

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
#define ll long long int
4+
5+
bool valid(ll x, int m, int n, int k){
6+
int cnt=0;
7+
for(int i=1;i<=m;i++){
8+
cnt+=n<x/i?n:x/i;
9+
if(x/i==0)break;
10+
}
11+
return cnt>=k;
12+
}
13+
14+
int findKthNumber(int n1, int n2, int k) {
15+
ll l=0, r=n1*n2,ans;
16+
while(l<=r){
17+
ll m = l +(r-l)/2;
18+
if(valid(m,n1,n2,k)){
19+
ans=m;
20+
r=m-1;
21+
}
22+
else{
23+
l=m+1;
24+
}
25+
}
26+
return ans;
27+
}
28+
};

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.