zoukankan      html  css  js  c++  java
  • CF1352C 【K-th Not Divisible by n】

    比赛的时候脑子糊了,简单结论题没想出来,最后乱搞了个二分过的((

    思路

    每次二分一个答案 (x)

    那么 (x) 之前无法算进答案的数的个数显然是 (lfloor frac{x}{n} floor)

    所以若答案是 (x) ,则在它之前符合条件的数就是 (x -lfloor frac{x}{n} floor)

    每次判断一下在它之前符合条件的数是否大于等于 (k) 即可。

    Code

    #include<iostream>
    #include<algorithm>
    #include<cstring>
    #include<cstdio>
    #include<bitset>
    #include<cmath>
    #include<queue>
    #include<map>
    #include<set>
    #define LL long long
    
    using namespace std;
    
    LL read()
    {
    	LL ans=0,f=1;
    	char c=getchar();
    	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
    	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    	return ans*f;
    }
    
    LL t,n,k,ans,l,r;
    
    int main()
    {
    	t=read();
    	while(t--)
    	{
    		n=read();k=read();
    		if(k<n)
    			printf("%lld
    ",k);
    		else
    		{
    			l=1,r=1e18;
    			while(l<=r)
    			{
    				LL mid=l+r>>1;
    				if(mid-mid/n>=k)
    				{
    					ans=mid;
    					r=mid-1;
    				}
    				else
    					l=mid+1;
    			}
    			printf("%lld
    ",ans);	
    		}
    		
    	}
    	return 0;
    }
    
  • 相关阅读:
    next_permutation( ) 和prev_permutation( ) 全排列函数
    F
    STL入门
    H
    C
    提交按钮组件
    JScorllPane面板(带滚轮的JPane)
    JPanel画板
    网络布局管理器
    边界布局管理器
  • 原文地址:https://www.cnblogs.com/blackbird137/p/13550382.html
Copyright © 2011-2022 走看看