Hello, friends. I did the fourth challenge on Project Euler and I'd like to know what I can do to improve the efficiency of my code. Right now it takes 1.562s to run and the source code is as follows: #include <iostream> #include <string.h> using namespace std; int Number = 0; int Reversed_Number = 0; int First_Number = 0; int Second_Number = 0; int Product = 0; int Biggest_Palindrome = 0; bool Is_Palindrome = false; string Text_Valued_Number = ""; string Text_Valued_Reversed_Number = ""; void Reverse_Number (int); void For_Loop (int,int); void Check_if_Number_is_a_Palindrome(int,int); void Show_Number(int); void For_Loop(int First_Number, int Second_Number) { for … |
+0 forum
5 | ||

Write a program that prompts the user for a value for i and displays the e value, and this is all i have so far. I was told it's suppose to have two for loops but i'm not sure where and how to do it and i know my output is wrong as well, also the use of a for loop is important. #include <iostream> using namespace std; int main (){ double count; double i=1; double e; cout<<"What is the value for i?"; cin>>i; for(count=1;count<=i;count++){ e!=1/count; cout<<"The value of e is equal to :"<<e<<endl; } system ("pause"); return 0; } |
+0 forum
1 | ||

Hey, guys. A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a² + b² = c². For example, 3² + 4² = 9 + 16 = 25 = 5². There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. #include <iostream> using namespace std; int a = 0; int b = 0; int c = 0; bool Found = false; int Find_Triplet(int,int,int); int Find_Triplet(int a, int b, int c) { for (int i = 5; i < 1000; i++) { c = i; … |
+0 forum
8 | ||

Hello, guys. This challenge asks us to find the 10001-th prime. Here's my code: // A reasonable approximation is to say that the n-th prime is such that p(n) = n*(log n + log*(log n) - 1). // With that in mind, we can say that the 10001-th prime is smaller than 10100*(log 10100 + log(log 10100) - 1), which we can round to 105000. #include <iostream> #include <cmath> #define MAX_INTERVAL 105000 using namespace std; int Wanted_Prime = 0; void Show_Prime(int); void Show_Prime(int Wanted_Prime) { cout << "The 10001-th prime is " << Wanted_Prime << endl; } int main() { … |
+0 forum
9 | ||

Hello, guys. The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 62229893423380308135336276614282806444486645238749 30358907296290491560440772390713810515859307960866 70172427121883998797908792274921901699720888093776 65727333001053367881220235421809751254540594752243 52584907711670556013604839586446706324415722155397 53697817977846174064955149290862569321978468622482 83972241375657056057490261407972968652414535100474 82166370484403199890008895243450658541227588666881 16427171479924442928230863465674813919123162824586 17866458359124566529476545682848912883142607690042 24219022671055626321111109370544217506941658960408 07198403850962455444362981230987879927244284909188 84580156166097919133875499200524063689912560717606 05886116467109405077541002256983155200055935729725 71636269561882670428252483600823257530420752963450 Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product? Here's how I did it: #include <iostream> #include <string> #include <vector> using namespace std; string Grid_of_Numbers = "73167176531330624919225119674426574742355349194934" "96983520312774506326239578318016984801869478851843" "85861560789112949495459501737958331952853208805511" "12540698747158523863050715693290963295227443043557" "66896648950445244523161731856403098711121722383113" "62229893423380308135336276614282806444486645238749" "30358907296290491560440772390713810515859307960866" "70172427121883998797908792274921901699720888093776" "65727333001053367881220235421809751254540594752243" "52584907711670556013604839586446706324415722155397" "53697817977846174064955149290862569321978468622482" "83972241375657056057490261407972968652414535100474" "82166370484403199890008895243450658541227588666881" "16427171479924442928230863465674813919123162824586" "17866458359124566529476545682848912883142607690042" "24219022671055626321111109370544217506941658960408" "07198403850962455444362981230987879927244284909188" … |
+0 forum
7 | ||

Hello, guys. Here's the challenge: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? I wrote my code: #include <iostream> #include <cmath> using namespace std; #define MAX_VALUE 2793510720 unsigned int Smallest_Evenly_Divisable = 0; void Show_Number(unsigned int); void Show_Number(unsigned int Smallest_Evenly_Divisable) { cout << "\n\n" << Smallest_Evenly_Divisable << endl; } int main() { unsigned i = 0; for (i = 2520; i < MAX_VALUE; i++) { if ( i % … |
+0 forum
7 | ||

Not usually one to have to do this, but I cannot find the problem with my code. Yes, this is a project Euler problem. Any tips or suggestions help. My code works by getting the location of each number, excluding the first numbers as it has to be predefined, and either adding one or keeping that value to find the location of the next number. The larger of those two numbers is appended to the final. The code DOES work on the 4 level test triangle provided. testNums = [] nextNum = row0 nextLocation = 0 final = [75] for … |
+0 forum
2 | ||

Hello , I am trying to solve some problems from the "Computer Simulation Methods" book. It says > > Write a class that solves the nuclear decay problem.Input the decay constant l from the control window.For l=1 and dt=0.01 ,compute the difference between the analytical result and the result of the euler algorithm for Nt/N0 at t=1 and t=2.Assume that time is measured in seconds. (The above is for java ,but I want to do it in c++). My question is how I will implement Euler algorithm. I know ,that in motion for example , the Euler algorithm goes as … |
+0 forum
22 | ||

I am trying problem 16 from project euler, i want to add a00 integers 50 decimal places each.So i searched and found BigIntegerLibrary, but can't find any good reference material on what are the varoius functions and operators in the library. Please provide me some decent material on how to use the library...... |
+0 forum
1 | ||

Currently I'm working on Euler Problem 62, Permutations of a cube, the program is searching for a cube that 5 of the permutations are other cubes, I did some online research and found that the cube that im searching for is within the range of an int64, Actually its 12 digits long, however when ever i test the program isnt producing the correct answer. The way i went about solving this problem is as so step 1- Generating all cubes within a range of 1 digit... //ie 10, 100, 1000, 10000 step 2- I digitize each cube and sort their … |
+0 forum
4 | ||

Hi, so the exercise I am supposed to do is : "If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000." So, the question is pretty simply, nothing hard to understand. Here is the function I did to get it : [CODE]#include <iostream> #include <string> using namespace std; int calculate(int max) { int result = 0; for(int i = 1; 5 * i < max ; i++) … |
+0 forum
2 | ||

I have been racking my brains to find what's wrong with my code... been playing with it for an hour or so but it seems to still be wrong.. Please anyone can point out the mistake? Im so frustated right now.:yawn: the answer to the question is 21124, but this program keeps giving me 21088 [CODE=c] /* If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the numbers from 1 to 1000 (one … |
+0 forum
2 | ||

Hi everyone. I was trying to solve Pb 35 on Project Euler ([url]http://projecteuler.net/index.php?section=problems&id=35[/url]). It essentially asks to write a program to list all circular primes under 1e6. I wrote the program and it works well for the most part. However, in the end it seems not to be able to conduct membership tests properly. For example, it lists 391 as a prime. I have looked it over and over but I can't figure out what's wrong. I will probably also try a new approach, but I want to know why this doesn't work. I [I]am[/I] new to programming, so please … |
+0 forum
6 | ||

Hi, I tried doing Project Euler #27 today, which asks the following: [QUOTE] Euler published the remarkable quadratic formula: n² + n + 41 It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 40^(2) + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and certainly when n = 41, 41² + 41 + 41 is clearly divisible by 41. Using computers, the incredible formula n² − 79n + 1601 was discovered, which produces 80 primes for the consecutive values n … |
+0 forum
22 | ||

I wrote the following function in Python3 for finding the largest product of numbers along the diagonal(top-left to right-bottom). [CODE=python] def GreatestOnDiagonal(data): '''Returns greatest product possible by multiplying 4 numbers in the diagonal ''' grtProduct=1 for item in data: for n in item: product=1 for r in range(0,4): try: d=data.index(item)+r e=item.index(n)+r product*=data[d][e] except IndexError: break # if product>grtProduct:grtProduct=product return grtProduct [/CODE] The parameter passed here,data, is a list of numbers from the grid in [url]http://projecteuler.net/index.php?section=problems&id=11[/url] . Each line is a list nested into the main list, data. What I've tried to do here is- Take 08 ,for example, which lies … |
+0 forum
15 |

The End.