After viewing the editorial for the Probem Musical Chairs , I tried it again on my ide.
The only difference in my code was that I changed if(n%i==0) to if(!n%i) and it gave wrong output for that. But if I use if(n%i==0) it is giving correct ouput and correct answer.
Can someone tell me what is happening?
#include"bits/stdc++.h"
#define ll long long int
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll ans=0;
n-=1;
for(ll i=1;i*i<=n;i++)
{
if(!n%i)
{
ans++;
if(i*i!=n)
ans++;
}
}
cout<<ans<<endl;
}
return 0;
}