1487B - Cat Cycle - CodeForces Solution


math number theory *1200

Please click on ads to support us..

Python Code:

for t in range(int(input())):
    n,k = map(int,input().split()); k -= 1
    a = n//2;g = k//a;e = k + g
    print([k%n+1,e%n+1][n%2])

C++ Code:

#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(long long  i=a;i<b;i++)
#define decrep(i,a,b)        for(long long  i=a;i>=b;i--)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define ll  long long
#define nl "\n"
#define pb push_back
#define no cout<<"NO\n"
#define yes cout<<"YES\n"
#define all(v) v.begin(),v.end()
#define dec(v) v.rbegin(),v.rend()
#define decimal(n) fixed<<setprecision(n)
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vll;
 
// #define set(name,data,size) memset(name,data,size);
 ll add(ll x)
 {
    ll mx=0;
    ll mn=10;
    while(x>0)
    {
       ll rem=x%10;
       x=x/10;
       mx=max(mx, rem);
       mn=min(mn, rem);
    }
    return mn*mx;
 
 
 }
 
 bool mycmp(pair<ll,ll>&a,pair<ll,ll>&b)
 {
      if(a.first< b.first)
      {
         return true;
      }
      else if(a.first==b.first && a.second< b.second)
       {
         return true;
       }
       return false;
 }

void dfs(ll src, ll n, vector<pair<ll,ll>>&v, vector<bool>&vis)
{
   vis[src]=true;
   for(ll i=0;i<n;i++)
   {
     if(  (v[i].first==v[src].first  || v[i].second==v[src].second )    && vis[i]==false)
        {
           dfs(i, n, v,vis);

        }
   }
}
void  jaishreekrishna()
{  



  ll n, k;
  cin>>n;
  cin>>k;

 if(n%2==0)
 {
    ll pos=k%n;
    if(pos==0)
    {
       cout<<n<<endl;
       return ;
    }
    cout<<pos<<endl;

   return ;
 }

 ll pos=k+(k-1)/(n/2);
 pos=pos%n;
    if(pos==0)
    {
       cout<<n<<endl;
       return ;
    }
    cout<<pos<<endl;
 


}

 
int main()
{
  ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
  int t;
  cin>>t;
















 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  while(t--)
  {
         jaishreekrishna();
  }
  cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
	cerr<<__DATE__<<nl<<__TIME__<<nl;
 
return 0;
 
}


Comments

Submit
0 Comments
More Questions

136. Single Number
169. Majority Element
119. Pascal's Triangle II
409. Longest Palindrome
1574A - Regular Bracket Sequences
1574B - Combinatorics Homework
1567A - Domino Disaster
1593A - Elections
1607A - Linear Keyboard
EQUALCOIN Equal Coins
XOREQN Xor Equation
MAKEPAL Weird Palindrome Making
HILLSEQ Hill Sequence
MAXBRIDGE Maximise the bridges
WLDRPL Wildcard Replacement
1221. Split a String in Balanced Strings
1002. Find Common Characters
1602A - Two Subsequences
1555A - PizzaForces
1607B - Odd Grasshopper
1084A - The Fair Nut and Elevator
1440B - Sum of Medians
1032A - Kitchen Utensils
1501B - Napoleon Cake
1584B - Coloring Rectangles
1562B - Scenes From a Memory
1521A - Nastia and Nearly Good Numbers
208. Implement Trie
1605B - Reverse Sort
1607C - Minimum Extraction