Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.
My solution approach is,
first made a smaller version of the problem then I tried to solve it after solving this I was going to solve the bigger version.
// b. print the last digit of p
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
#include<stdio.h> | |
#include<math.h> | |
// a. find out p=2^15 | |
// b. print the last digit of p | |
int main() | |
{ | |
int ans,i,n,j; | |
n=10; | |
ans=2; | |
for(i=2;i<=15;i++){ | |
ans=ans*2; | |
ans=ans%10; // if I want to know the last one digit of the number of the sum of the sequence | |
} | |
printf("ans :%d",ans); | |
return 0; | |
} | |
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
/// Euler problem 48 | |
#include<stdio.h> | |
#include<math.h> | |
int long long power(int long long n); | |
int main() | |
{ | |
int long long ans,i,j; | |
ans=0; | |
for(i=1;i<=1000;i++){ | |
ans= ans+power(i); | |
ans=ans%10000000000; | |
} | |
printf("ans :%lld",ans); | |
return 0; | |
} | |
int long long power(int long long n) | |
{ | |
int i; | |
int long long p=1; | |
for(i=1;i<=n;i++){ | |
p=p*n; | |
p=p%10000000000; | |
} | |
return p; | |
} |