Because it is Python
No problem, keep interested, keep asking, thatβs the proper way to learn things, good luck
1 Like
Can anyone explain me why we must use the bool array as in this example.?
Blockquote
s=d;
has[s]=1;//boolean has[1000001]
arr[0]=s;
k=1;
for(i=1;i<n;++i)
{
s = (((((a*(s*s)%m)%m)+((b*s)%m))%m)+(c%m))%m;
if(has[s])
{
break;
}
else
{
arr[k++]=s;
has[s]=1;
}
}
if(i==n)flag=1;
for(i=0;i<k;++i)
{
if(arr[i]==s)break;
}
pos=i;
Can anyone explain me why we must use the bool array as in this example.?
Blockquote
s=d;
has[s]=1;//boolean has[1000001]
arr[0]=s;
k=1;
for(i=1;i<n;++i)
{
s = (((((a*(s*s)%m)%m)+((b*s)%m))%m)+(c%m))%m;
if(has[s])
{
break;
}
else
{
arr[k++]=s;
has[s]=1;
}
}
if(i==n)flag=1;
for(i=0;i<k;++i)
{
if(arr[i]==s)break;
}
pos=i;
t = int(input())
n=a=b=c=d = 0
Ans = []
def S(i):
if stre[i] != None:
return stre[i]
elif i==0:
stre[i] = d
return stre[i]
else:
stre[i] = int((a*(S(i-1)**2) + b*S(i-1) + c) % 1000000)
return stre[i]
def prog():
S(n-1)
stre.sort()
sum1 = sum2 = 0
for x in range(n):
if x % 2 != 0:
sum1 += stre[x]
else:
sum2 += stre[x]
return abs(sum1-sum2)
for i in range(t):
n,a,b,c,d = [int(x) for x in input().split()]
stre = [None]*n
Ans.append(prog())
for i in Ans:
print(i)
This is giving NZEC error. Can someone please help me?
Can someone please tell me why this code is not a correct solution for the question? There is no need to even sort here.
Solution Link β CodeChef: Practical coding for everyone