Created
June 20, 2020 11:00
-
-
Save u7karshs/03f27c2800601bf020e7b9469f5b22f2 to your computer and use it in GitHub Desktop.
Last digit of sum of n i.e till (Fn) term
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Uses python3 | |
| import array as arr | |
| def summ(ara,t): | |
| s=0 | |
| for i in range (0,t): | |
| s=s+ara[i] | |
| return s | |
| def fiboH(n): | |
| ar=arr.array('L',[0]) | |
| ar.append(1) | |
| p=-1 | |
| a=0 | |
| b=1 | |
| for i in range (2,n+1): | |
| c=b+a | |
| a=b | |
| b=c | |
| ar.append(c%10) | |
| if((ar[i-1]==0) & (ar[i]==1)): | |
| p=i-1 | |
| break | |
| if(p!=-1): | |
| print((summ(ar,p)*(n//p) + summ(ar,n%p+1))%10) | |
| else: | |
| print((summ(ar,n+1))%10) | |
| if __name__== "__main__": | |
| a=int(input()) | |
| (fiboH(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment