Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Self powers
- Problem 48
- The series, 1**1 + 2**2 + 3**3 + ... + 10**10 = 10405071317.
- Find the last ten digits of the series, 1**1 + 2**2 + 3**3 + ... + 1000**1000.
- */
- const fp = require('lodash/fp');
- const object = require('lodash/fp/object');
- const extend = require('lodash/fp/extend');
- let modulo = 1e10;
- let ns = n => fp.range(1,n+1);
- let compute = n => fp.reduce((a,v) => fn(a,v),0)(ns(n));
- function fn(a,v){
- let t = v;
- for(let i=1; i<v; i++){
- t *= v;
- t %= modulo;
- }
- a += t;
- return a;
- }
- let solution = fp.compose(
- fp.join(''),
- fp.takeLast(10),
- fp.toString
- )(compute(1000));
Add Comment
Please, Sign In to add comment