Posts

Project Euler Problem 717 Summation of a Modular Formula - Solution

Image
Summation of a Modular Formula          Problem 717 For an odd prime  p p , define  f ( p ) = ⌊ 2 ( 2 p ) p ⌋ mod 2 p f ( p ) = ⌊ 2 ( 2 p ) p ⌋ mod 2 p For example, when  p = 3 p = 3 ,  ⌊ 2 8 / 3 ⌋ = 85 ≡ 5 ( mod 8 ) ⌊ 2 8 / 3 ⌋ = 85 ≡ 5 ( mod 8 )  and so  f ( 3 ) = 5 f ( 3 ) = 5 . Further define  g ( p ) = f ( p ) mod p g ( p ) = f ( p ) mod p . You are given  g ( 31 ) = 17 g ( 31 ) = 17 . Now define  G ( N ) G ( N )  to be the summation of  g ( p ) g ( p )  for all odd primes less than  N N . You are given  G ( 100 ) = 474 G ( 100 ) = 474  and  G ( 10 4 ) = 2819236 G ( 10 4 ) = 2819236 . Find  G ( 10 7 ) This problem is not really that complicated to reduce to acceptable execution time. (Python, ~8hrs in 1 thread on a typical laptop.) Please leave a comment if you have better solution or suggestion. See note below. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17...

Uber Price Discrimination - different user has different price for exact same pickup/dropoff

Image
Recently, I start to notice that Uber shows significantly different price for the exact same route using my account or my husband's account. UberX from my home to airport shows $39 with my account and it goes up to $46 with my husband's account. I guess he uses Uber a lot more often than I did, and Uber figured they could charge him more. Everyone is talking about surge pricing, pool vs x, but not this. Price discrimination is everywhere. Check the price with your friend's phone next time and see it for yourself.

Project Euler Problem 521 Smallest prime factor - Solution

Image
Smallest prime factor     Problem 521 Let smpf( n ) be the smallest prime factor of  n . smpf(91)=7 because 91=7×13 and smpf(45)=3 because 45=3×3×5. Let S( n ) be the sum of smpf( i ) for 2 ≤  i  ≤  n . E.g. S(100)=1257. Find S(10 12 ) mod 10 9 . If you didn't already, read Hint 1 and Hint 2 first.  Below is an implementation based on ideas from Hint 1 and Hint 2, with some performance tuning in place. Below c++ code reaches correct answer in ~1 hour. #include <iostream> #include <vector> using namespace std; int main () { const long long maxp = 1000000 ; const long long maxbillion = 100 ; const long long maxp2 = 10000000000 ; const long long maxarrsize = maxp2 + 1 ; const long long mod = 1000000000 ; std :: vector < bool > primemap( maxp + 1 , true ); std :: vector < long long > arrp = {}; long long sum1 = 0 ; for ( long ...