zoukankan      html  css  js  c++  java
  • D

    KazaQ wears socks every day.

    Before the first day, he has nn pairs of socks in his closet, labeled from 11 to nn.

    Every morning, he would put on a pair of socks with the smallest label in the closet.

    Every evening, he would take off socks and put them into a basket. After that, if there are (n1)(n−1) pairs of old socks in the basket, lazy KazaQ will have to wash them. These socks can be dried out on the next day and then will be put back to the closet in the evening.

    KazaQ would like to know which pair of socks he would wear on the kk-th day.

    Input

    The input contains multiple (about 20002000) test cases.

    Each test case in only one line contains two integers nn, kk (2n1092≤n≤109, 1k10181≤k≤1018).

    Output

    For each test case, output "Case #x: y" in one line (without quotes), where xxindicates the case number starting from 11, and yy denotes the answer to the corresponding case.

    Example

    Input
    3 7
    3 6
    4 9
    
    Output
    Case #1: 3
    Case #2: 1
    Case #3: 2

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    typedef long long lli;
    using namespace std;
    const int  mxn = 1e9;
    int main()
    {
    
        lli n,k,cnt=1;
        while(cin>>n>>k)
        {
            cout<<"Case #"<<cnt++<<": ";
            if(k<=n)
                cout<<k<<endl;
            else
            {
                lli ans = (k-n)%(n-1);
                if(ans<n-1 && ans)
                {
                    cout<<ans<<endl;
                }
                else
                {
                    lli col = (k-n)/(n-1);
                    if(col&1)
                        cout<<n-1<<endl;
                    else
                        cout<<n<<endl;
                }
            }
    
        }
        return 0;
    }
    所遇皆星河
  • 相关阅读:
    h5唤起app
    app唤起的完美解决方案,及阻止浏览器的默认弹窗行为
    cdn
    函数声明和函数表达式的区别
    基础系列(7)—— 结构
    基础系列(4)—— C#装箱和拆箱
    重温软件工程——对软件工程的初步了解
    基础系列(9)—— 抽象方法和接口
    自学系列--git的基础简介
    设计模式之简单工厂模式
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11623512.html
Copyright © 2011-2022 走看看