Chefina and Swap SOLUTIONS CHFNSWAP

Chefina and Swap SOLUTION

You are given a positive number N. Consider the grouping S=(1,2,… ,N). You ought to pick two components of this succession and trade them. 
 
A trade is decent if there is a number M (1≤M<N) with the end goal that the whole of the primary M components of the subsequent succession is equivalent to the aggregate of its last N−M components. Locate the quantity of pleasant trades. 
 
Info 
 
The main line of the info contains a solitary number T meaning the quantity of experiments. The portrayal of T experiments follows. 
 
The solitary line of each experiment contains a solitary number N. 
 
Yield 
 
For each experiment, print a solitary line containing one number ― the quantity of decent trades. 
 
Imperatives 
 
1≤T≤106 
 
1≤N≤109 
 
Subtasks 
 
Subtask #1 (10 focuses): 
 
T≤10 
 
N≤103 
 
Subtask #2 (30 focuses): 
 
T≤10 
 
N≤106 
 
Subtask #3 (60 focuses): unique imperatives 
 
Model Input 
 
 
 
 
 
 
 
Model Output 
 
 
 
 
 
3
 
 
LOGIC VIDEO HAS BEEN REMOVED

31 thoughts on “Chefina and Swap SOLUTIONS CHFNSWAP”

  1. I think when there will be 3 days to end or 5 days then i think this codechef may permit till then i think we need to try our own put please share any logic we dont want code just logic will do thanks man

    Reply
  2. #include
    using namespace std;

    int main()
    {
    int t;
    cin>>t;

    while(t–)
    {
    int n,num;
    cin >> n;

    num = (n+1)/2;

    if(num%2)
    cout<<"0"<<endl;
    else
    cout<<(num/2)+1<<endl;
    }
    return 0;
    }

    Can someone point out the mistake?

    Reply
  3. # cook your dish here
    t=int(input())
    import itertools
    def chefswap(n,arr):
    hell = list(itertools.combinations(range(n), 2))
    m=0
    for i,j in hell:
    c=0
    arr[i],arr[j]=arr[j],arr[i]
    for k in range(n-1):
    arr1=sum(arr[0:k+1:1])
    arr2=sum(arr[k+1:n:1])
    if arr1==arr2:
    c=c+1
    if c!=0:
    m=m+1
    arr[i],arr[j]=arr[j],arr[i]
    return m

    for _ in range(t):
    n=int(input())
    arr=[]
    for i in range(1,n+1):
    arr.append(i)
    if n==1 or n==2:
    print(0)
    else:
    result=chefswap(n,arr)
    print(result)

    There is time limit error.

    Reply

Leave a Comment

close
error: Content is protected !!
Free Udemy Courses and Hacking Resources Join Us on TelegramClick Here
+