Skip to content

Commit 2d450a1

Browse files
Merge pull request #734 from goflora/patch-4
Create computeXOR1toN.py
2 parents 52f3aea + 2c792f8 commit 2d450a1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

BIT/ComputeXOR1toN/computeXOR1toN.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#Direct XOR of all numbers from 1 to n
2+
def computeXOR( n)
3+
4+
if (n % 4 == 0) :
5+
return n
6+
if (n % 4 == 1) :
7+
return 1
8+
if (n % 4 == 2) :
9+
return n + 1
10+
else :
11+
return 0
12+
13+
n = input("enter N")
14+
print(computeXOR(n))

0 commit comments

Comments
 (0)