Project Euler #3 with Python

I tried to solve some Euler’s problems, this is the solution I found for problem #3 with Python. The problem asks:

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?

Can you, please, suggests me improvements?

def get_largest_prime2(value):     start = time.clock() #used to measure the execution time     divisors = []  #this list will be filled with all number's divisors     i = 1     while value != 1:          while value%i == 0: #check if the value can be divided by i and, if so, iterate the process.             value = (value // i)             divisors.append(i)             if i == 1 : break #it's needed to avoid an infinity loop         if i >= 3: i += 2 #when i is bigger than 3, search divisors among odd numbers( this reduces the search field)         else: i += 1       print( time.clock()-start)     return max(divisors) #returns the max prime divisors 

Elixir solution for Project Euler #2

I have already done many of the Project Euler questions in other languages before, but whenever learning a new language, I like to do the problems again in that language.

Here is my elixir version of

Find the sum of all fibbonaci numbers below 4,000,000.

stream = Stream.unfold({0,1}, fn {a, b} -> {a, {b, a + b}} end) Enum.reduce_while(stream, 0, &(     cond do         &1 < 4000000 and rem(&1, 2) == 0 ->             {:cont, &2 + &1}         &1 < 4000000 ->             {:cont, &2}         true ->             {:halt, &2}     end )) 

Can anyone spot a way to make my code fit the elixir paradigm more? Are there things I could improve?

Euler characteristics in the rank one case

Suppose $ E$ is an elliptic curve over a number field with good ordinary reduction at the primes above a fixed odd prime $ p$ . We are interested in the Iwasawa theory over the cyclotomic $ \mathbb{Z}_p$ extension under the additional assumption that $ E$ has a point of infinite order and also that $ L(E,s)$ has a simple zero at $ s=1$ .

Is there a definition of a modified Euler characteristic for the Selmer group over the cyclotomic extension which can be related to the derivative $ L'(E,1)$ in the framework of the BSD conjecture? Can someone give me some precise references.

bare hand integration of euler class of blow up of a complex surface at a point

let X be a product of two Riemann surface of genus $ \geq1$ and p be a point of X. If X’ is the blow up of X at p. Let E denote the exceptional divisor I am aware that the the second Chern number of X’ since it’s the euler characteristic. I would to verify this by integration of the second chern class. Up to now I try as follows:

Let W be a tubular neighborhood of the exceptional divisor E. Let N be the normal bundle of E $ c_2(X’) = p^*(c_2(X))+c_2(TN)=p^*(c_2(X))+ c_1(TE)c_1(N)$ Now I am not sure how to proceed. $ \int_{X’}p^*(c_2(X))+ c_1(TE)c_1(N)$ This reduces to $ \int_{X’}c_1(TE)c_1(N)$ which I tend to understand as the intersection number. But usually one performs this computation in $ \mathbb{C}P^n$ , which is not the case here. Could anybody give me some help? Thanks.

Project Euler #7 10001st prime in C++


By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

How to optimize this code?

#include <iostream>  bool is_prime(int num) {     for (int i = 2; i <= num/2; ++i)     {         if (num % i == 0)         {             return false;         }     }     return true; }  int main() {     int count = 2;     for (int i = 5; ; i = i+2)     {         if (is_prime(i))         {             count++;         }         if (count == 10001)         {             std::cout << i;             return 0;         }     } } 

Project Euler #1 : Finding the sum of multiples of 3 and 5 under a given number

I wrote the following code in c++14 for hackerRank Project Euler challenge 1.

First I came up with a naive solution by iteration and passed most test cases except 2 and 3 due to timeout as solution is O(N) and test cases 2 and 3 have large input.

The below code is my second attempt at a solution. ALthough I pass the sample test case 0 and custom test case successfully, while attempting to submit I fail at all hidden cases except case 5. I can’t seem to figure out, how do I proceed further. Is my code logic flawed and failing at edge cases that I dont seem to figure out or there is some other issue with the code.

As I am just starting out, please enlighten me with standardised way of doing things.

# include <iostream>  long T; long N;  /* Naive Solution 2 test cases failed due to timeout time complexity O(N)  int Sum_multiple_3and5 (int n) {  int sum = 0;  for (int j = 1; j < N; j++)  {    if ((j % 3 == 0) || (j % 5 == 0))    {      sum = sum + j;    }  }  return sum ; } */  long Sum_multiple_3and5(long n)  { long Given_No = n; long Kfor3 = (Given_No - 1) / 3; //std::cout << Kfor3 << "\n"; long Kfor5 = (Given_No - 1) / 5; //std::cout << Kfor5 << "\n"; long SKfor3 = (((Kfor3) * (3 + (3 * Kfor3))) /2); //std::cout << SKfor3 << "\n"; long SKfor5 = (((Kfor5) * (5 + (5 * Kfor5))) /2); //std::cout << SKfor5 << "\n"; long KforExtraSum = (Given_No - 1) / 15; //std::cout << KforExtraSum << "\n"; long SKforExtraSum = (KforExtraSum /2) * (15 + (15 * KforExtraSum)); //std::cout << SKforExtraSum << "\n"; long sum = ((SKfor3 + SKfor5) - SKforExtraSum); //std::cout << sum << "\n"; return sum; }  /* using sum of sequence formula to sum multiples of 3  to multiple of 5 and subtract from the total the  sum of multiples of 15 */  int main()  { std::cin >> T;  for ( long i = 0; i<T;i++) {  std::cin >> N; std::cout << Sum_multiple_3and5(N) << std::endl; } return 0; }     

Casson invariant and Euler characteristic

A slogan I frequently hear is: “the Casson invariant is the Euler characteristic of the Floer homology of flat SU(2)-connections on the integral homology sphere”. Is there a single paper/reference that essentially states this as a result? It has been difficult to locate precise definitions. In addition, a sketch of how this works would be very helpful.

Derivation of the vortex filament equation from Euler equation

How can the vortex filament equation $ $ \partial_t \chi = \partial_s \chi \wedge \partial_{ss} \chi,$ $ where $ \chi(t,s)$ is a curve in $ \mathbb R^3$ , be derived from the Euler equation $ $ \partial_t \omega + v\cdot \nabla \omega = \omega \cdot \nabla v, \quad \operatorname{div} v = 0,$ $ where $ v:\mathbb R \times \mathbb R^3 \to \mathbb R^3$ , and $ \omega = \operatorname{curl}(v):\mathbb R \times \mathbb R^3 \to \mathbb R^3.$


I’ve asked a more general question at Survey on the vortex filament equation.