C/C++

28 - number spiral diagonals

Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: It can be verified that the sum of the numbers on the diagonals is 101. What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way? link cevap : 669171001 Derleme ortami Visual studio community c++ »

29 - distinct powers

Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5: If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms: 4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125 How many distinct terms are in the sequence generated by a^b for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100? »

3 - largest prime factor

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? link cevap : 6857 #include <stdio.h> #pragma hdrstop #include <tchar.h> #pragma argsused int _tmain(int argc, _TCHAR* argv[]) { int i,j,k = 0; unsigned int *divider; unsigned int counter = 0; unsigned long long test_number = 600851475143; // asal bolenleri test edilecek olan sayi // bolenlerin sayisi for(i = 2; i<=test_number; i++) { if(test_number%i == 0) { counter++; } } divider = (unsigned int *) calloc(counter, sizeof(unsigned int)); // divider dizisini temizle for(i=0; i<=counter; i++) { divider[i] = 0; } // bolen rakamlar sira ile tutuluyor for(i = 2; i<=test_number; i++) { if(test_number%i == 0) { divider[k] = i; k++; } } // bolenleri ekrana bas printf("tum bolenler:\n"); for(i=0; i<=counter; i++) { if(divider[i] ! »

4 - largest palindrome product

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. link cevap: 906609 #include <stdio.h> #include <math.h> #pragma hdrstop #include <tchar.h> // global degiskenler unsigned int carpim; unsigned char terslendi = 0; // todo : bunun ismini degistir unsigned int basamak_sayisi; unsigned int mod; unsigned int carpan_1; unsigned int carpan_2; unsigned int *basamaklar; // fonksiyon prototipleri void carpma(); unsigned char tersleniyormu(unsigned int); unsigned int basamak_sayisi_hesapla(unsigned int); #pragma argsused int _tmain(int argc, _TCHAR* argv[]) { carpma(); system("pause"); } void carpma() { for (carpan_1 = 100; carpan_1 < 1000; carpan_1++) { for (carpan_2 = 100; carpan_2 < 1000; carpan_2++) { carpim = carpan_1 * carpan_2; terslendi = tersleniyormu(carpim); // tum terslenen sayilari ekrana bas if (! »

5 - smallest multiple

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? link cevap : 232792560 #include <stdio.h> #pragma hdrstop #include <tchar.h> // fonksiyon prototipleri unsigned int okek_hesapla(unsigned int, unsigned int); // global degiskenler unsigned int a, b; #pragma argsused int _tmain(int argc, _TCHAR* argv[]) { unsigned int okek; b = 1; for (a = 1; a<20; a++) { okek = okek_hesapla(a, b); b = okek; } printf("Sonuc = %d\n", okek); system("pause"); } unsigned int okek_hesapla(unsigned int sayi_1, unsigned int sayi_2) { unsigned int i; for (i=1; i<=sayi_1*sayi_2; i++ ) { if ( i%sayi_1==0 && i%sayi_2==0) { break; } } return i; } »

6 - sum square difference

The sum of the squares of the first ten natural numbers is, The square of the sum of the first ten natural numbers is, Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640. Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum. »

67 - maximum path sum II

By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top to bottom in triangle.txt (right click and ‘Save Link/Target As…’), a 15K text file containing a triangle with one-hundred rows. NOTE: This is a much more difficult version of this. »

7 - 10001st_prime

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? link cevap : 104743 #include <stdio.h> #pragma hdrstop #include <tchar.h> // fonksiyon prototipleri unsigned char sayi_asal_mi(unsigned int, unsigned int *); #pragma argsused int _tmain(int argc, _TCHAR* argv[]) { unsigned int analiz_sayisi = 110000; unsigned int i,j; unsigned int counter=0; unsigned char sayi_asal_flag=0; unsigned int sayi_asal_counter = 0; for (i=2; i<analiz_sayisi+1; i++) { sayi_asal_flag = sayi_asal_mi(i, &counter); counter = 0; sayi_asal_counter = sayi_asal_flag + sayi_asal_counter; if (sayi_asal_counter == 10001) { break; } } printf("10001. »

8 - largest product in a series

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? link cevap : 40824 #include <stdio.h> #pragma hdrstop #include <tchar. »

9 - special pythagorean triplet

A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, For example, There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. link cevap : 31875000 #include <stdio.h> #include <math.h> #pragma hdrstop #include <tchar.h> #pragma argsused int _tmain(int argc, _TCHAR* argv[]) { unsigned int a,b,c,multiplication; for (a = 1; a < 1000; ++a) { b = (500000-1000*a)/(1000-a); c = sqrt(a*a + b*b); if ((a+b+c) == 1000) { break; } } multiplication = a*b*c; return 0; } »