Skip to content

Commit 2c792f8

Browse files
authored
Create computeXOR1toN.py
1 parent 52f3aea commit 2c792f8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
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)