Project Euler -- 48 (Self powers)

Problem : The series, 11 + 22 + 33 + ... + 1010 = 10405071317.
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.

// a. find out p=2^15

// b. print the last digit of p




#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;
}
view raw gistfile1.c hosted with ❤ by GitHub



/// 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;
}

Related Posts: