Algo Vision
Bir ajoib va menimcha hammaga tezda tushunarli buladigan masalani sizlar bilan bo'lishmoqchiman. Menimcha hamma faktorial haqida xabari bor. n! (yoki n faktorial) bu 1 dan n gacha bo'lgan barcha sonlar ko'paytmasi. Masalan: 4!=1*2*3*4 5!=1*2*3*4*5 .....…
en:
I want to share with you an interesting problem that I think will be easy for everyone to understand.
I believe everyone is familiar with the concept of a factorial.
n! (or n factorial) is the product of all numbers from 1 to n.
For example:
4! = 1 × 2 × 3 × 4
5! = 1 × 2 × 3 × 4 × 5
...
So, n! = 1 × 2 × 3 × 4 × ... × n (and by convention, 0! = 1).
Hopefully, everyone understands this so far.
The problem:
If the digit d is written n! times on the board, which odd numbers will it be divisible by?
(This is one of the simple problems from Codeforces.)
Given:
n = 1...10^9
Example:
d = 1, n = 3
3! = 1 × 2 × 3 = 6
Writing 1 6 times gives us 111111. Which odd numbers is this divisible by?
Odd numbers: 1, 3, 5, 7, 9
From these, 111111 is divisible by 1, 3, and 7.
Leave your algorithm in the comments!
#math
#logick
I want to share with you an interesting problem that I think will be easy for everyone to understand.
I believe everyone is familiar with the concept of a factorial.
n! (or n factorial) is the product of all numbers from 1 to n.
For example:
4! = 1 × 2 × 3 × 4
5! = 1 × 2 × 3 × 4 × 5
...
So, n! = 1 × 2 × 3 × 4 × ... × n (and by convention, 0! = 1).
Hopefully, everyone understands this so far.
The problem:
If the digit d is written n! times on the board, which odd numbers will it be divisible by?
(This is one of the simple problems from Codeforces.)
Given:
n = 1...10^9
Example:
d = 1, n = 3
3! = 1 × 2 × 3 = 6
Writing 1 6 times gives us 111111. Which odd numbers is this divisible by?
Odd numbers: 1, 3, 5, 7, 9
From these, 111111 is divisible by 1, 3, and 7.
Leave your algorithm in the comments!
#math
#logick
⚡3👍2
#include <iostream>
#include <cmath>
bool isPrime(int number) {
if (number <= 1) {
return false; // 0 and 1 are not prime numbers
}
if (number == 2) {
return true; // 2 is a prime number
}
if (number % 2 == 0) {
return false; // Even numbers greater than 2 are not prime
}
for (int i = 3; i <= std::sqrt(number); i += 2) {
if (number % i == 0) {
return false; // Divisible by a number other than 1 and itself
}
}
return true;
}
int main() {
int number;
std::cout << "Enter a number: ";
std::cin >> number;
if (isPrime(number)) {
std::cout << number << " is a prime number.\n";
} else {
std::cout << number << " is not a prime number.\n";
}
return 0;
}
Code Review
Bu yerda tub sonni aniqlaydigan sodda kod berilgan.
Bu kodni har tomonlama optimizatsiya qilsa bo'ladi!
Fikringizni izohlarda qoldiring
This code can be optimized in many ways.
What are your suggestions? Share your thoughts in the comments! 🚀
😐3
⚡3
Algo Vision
Qaysi OS dan ko'proq foydalanasiz
Stream utkazsam qaysi mavzuda bulishini xohlaysz.
Algoritmlar
Productiv C++
Algoritmlar
Productiv C++
⚡5
Sieve of Eratosthenes in C++: Spot the Errors and Improve the Code!
Here's an implementation of the "Sieve of Eratosthenes" algorithm in C++.
At first glance, the code seems functional, but it contains a few mistakes and areas for improvement. This is a great opportunity for you to practice your code review skills!
Task: Spot the issues in the code and suggest how it can be optimized or written more effectively. Share your thoughts in the comments!
Qo'yida sizga "Eratosfen g'alviri" nomli tub sonlarni maksimal tez aniqliydigan algoritm berilgan.
Algoritm goyasi kodda tuliq ifodanalangna lekin bazi bir kichik xatolar va kamchiliklar mavjud.
Bazi kamchiliklar til bilan boglangan bazilar esa yo'q
Xo'sh siz algoritmni dasturiy shaklni yanada optimal ko'rinishga keltirish uchun qanday fikr bera olasz?
Fikringizni izohlarda qoldiring.
#review
#algorithm
Here's an implementation of the "Sieve of Eratosthenes" algorithm in C++.
At first glance, the code seems functional, but it contains a few mistakes and areas for improvement. This is a great opportunity for you to practice your code review skills!
Task: Spot the issues in the code and suggest how it can be optimized or written more effectively. Share your thoughts in the comments!
Qo'yida sizga "Eratosfen g'alviri" nomli tub sonlarni maksimal tez aniqliydigan algoritm berilgan.
Algoritm goyasi kodda tuliq ifodanalangna lekin bazi bir kichik xatolar va kamchiliklar mavjud.
Bazi kamchiliklar til bilan boglangan bazilar esa yo'q
Xo'sh siz algoritmni dasturiy shaklni yanada optimal ko'rinishga keltirish uchun qanday fikr bera olasz?
Fikringizni izohlarda qoldiring.
#include <iostream>
#include <vector>
void sieveOfEratosthenes(int n) {
std::vector<bool> primes(n); // Using a vector to store prime numbers
for (int i = 0; i < n; i++) {
primes[i] = true; // Initialize all numbers as prime
}
primes[0] = primes[1] = false; // 0 and 1 are not prime numbers
for (int p = 2; p < n; p++) { // Iterating up to n instead of sqrt(n)
if (primes[p]) { // If the number is still marked as prime
for (int i = p * p; i < n; i += p) { // Start marking multiples from p * p
primes[i] = false; // Mark multiples as non-prime
}
}
}
// Print prime numbers
std::cout << "Prime numbers up to " << n << ": ";
for (int i = 2; i < n; i++) {
if (primes[i]) {
std::cout << i << " ";
}
}
std::cout << std::endl;
}
int main() {
int n = 50; // Fixed value for testing
sieveOfEratosthenes(n);
return 0;
}
#review
#algorithm
👍9
Algo Vision
#include <iostream>
#include <cmath>
bool isPrime(int number) {
if (number <= 1) {
return false; // 0 and 1 are not prime numbers
}
if (number == 2) {
return true; // 2 is a prime number
}
if (number % 2 == 0) {
return false; // Even numbers greater than 2 are not prime
}
for (int i = 3; i <= std::sqrt(number); i += 2) {
if (number % i == 0) {
return false; // Divisible by a number other than 1 and itself
}
}
return true;
}
int main() {
int number;
std::cout << "Enter a number: ";
std::cin >> number;
if (isPrime(number)) {
std::cout << number << " is a prime number.\n";
} else {
std::cout << number << " is not a prime number.\n";
}
return 0;
}
#include <cmath>
bool isPrime(int number) {
if (number <= 1) {
return false; // 0 and 1 are not prime numbers
}
if (number == 2) {
return true; // 2 is a prime number
}
if (number % 2 == 0) {
return false; // Even numbers greater than 2 are not prime
}
for (int i = 3; i <= std::sqrt(number); i += 2) {
if (number % i == 0) {
return false; // Divisible by a number other than 1 and itself
}
}
return true;
}
int main() {
int number;
std::cout << "Enter a number: ";
std::cin >> number;
if (isPrime(number)) {
std::cout << number << " is a prime number.\n";
} else {
std::cout << number << " is not a prime number.\n";
}
return 0;
}
#include <iostream>
#include <cmath>
constexpr bool isPrime(int number) {
if (number <= 1) return false;
if (number <= 3) return true;
if (number % 2 == 0 || number % 3 == 0) return false;
for (int i = 5; i * i <= number; i += 6) {
if (number % i == 0 || number % (i + 2) == 0) {
return false;
}
}
return true;
}
int main() {
int number;
std::cin >> number;
for(int i = 1; i <= number; i++){
if(isPrime(i))
std::cout << i << " ";
}
return 0;
}
Bu review qilingan variantlardan biri.
Xo'sh endi siz isbotlangchi nega bu har doim to'gri ishlashi kerak?
Umumiy olganda algoritm O(\|N)
Review qilganimizda imkon qadar ortiqcha if else lardan va bir const narsani qayta qayta hisoblashdan (sqrt(N))
voz kechishimiz kerak. Albatta zamonaviy C++ kompilerlar juda aqlli ular bu amallarni maksimal bajarashida (Lekin bu yerda umumiy dasturlash tiliga boglanmasdan olingan)
⚡8
Algo Vision
#include <iostream> #include <cmath> constexpr bool isPrime(int number) { if (number <= 1) return false; if (number <= 3) return true; if (number % 2 == 0 || number % 3 == 0) return false; for (int i = 5; i * i <= number; i += 6) { …
Va albatta bitta narsaga etibor berilishi kerak
C++ dasturlashda consteval va constexpr tushunchalar bor.
Bu kalid so'zlar bilan ifodalangan ifoda o'zgaruvchi yoki funksiyalar compile vaqtda hisoblanishi mumkin.
Bu degani dasturni ishga tushurganimizda uni hisoblash uchun alohida vaqt talab qilinmaydi.
Yuqoridagi kodda bu narsa ishlaymaydi va hech qanday effekt bermaydi.
Chunki biz funksiyani non-const qiymat bilan chaqiriyapmiz.
Bu holda barcha amallar compilyatsiya jarayonida bajariladi
C++ dasturlashda consteval va constexpr tushunchalar bor.
Bu kalid so'zlar bilan ifodalangan ifoda o'zgaruvchi yoki funksiyalar compile vaqtda hisoblanishi mumkin.
Bu degani dasturni ishga tushurganimizda uni hisoblash uchun alohida vaqt talab qilinmaydi.
Yuqoridagi kodda bu narsa ishlaymaydi va hech qanday effekt bermaydi.
Chunki biz funksiyani non-const qiymat bilan chaqiriyapmiz.
int main() {
constexpr int number = 15555;//bu ham compile timeda hisoblanadi
if(isPrime(number))
std::cout <<"Tub" << "";
return 0;
}
Bu holda barcha amallar compilyatsiya jarayonida bajariladi
⚡6🆒1
Which of the following expressions always correctly checks if the number N is even?
Qo'yidagi qaysi ifoda sonni juftligini doimo to'gri tekshiradi
Qo'yidagi qaysi ifoda sonni juftligini doimo to'gri tekshiradi
Anonymous Poll
28%
N & 1 == 0
73%
N % 2 == 0
13%
N | 1 == 0
28%
(N>>1)<<1==N
😨4
Yuqoridagi kod qanday natija qayataradi. (Queue bu navbat malumoatlar strukturas)
Anonymous Quiz
33%
1
28%
2
17%
3
21%
Compile Error
Yuqoridagi kodda kiruvchi ma'lumot dinamik yane o'zgaruvchan.
Bir marta 10 kiritilsa keyingi marta 100.
Lekin >0 bulishi aniq.
Xo'sh sizningcha kodda yozilgan algoritm umumiy nechta amal bajaradi?
(count_if yane bunda 0 lar sonini hisoblaydi) Qanday turdagi algoritmga tegishli.
O(N)-N ta amal
O(1)-1 ta amal
Javobingizni izohlarda qoldiring.
Bir marta 10 kiritilsa keyingi marta 100.
Lekin >0 bulishi aniq.
Xo'sh sizningcha kodda yozilgan algoritm umumiy nechta amal bajaradi?
(count_if yane bunda 0 lar sonini hisoblaydi) Qanday turdagi algoritmga tegishli.
O(N)-N ta amal
O(1)-1 ta amal
Javobingizni izohlarda qoldiring.
👍6
Algo Vision
Yuqoridagi kodda kiruvchi ma'lumot dinamik yane o'zgaruvchan. Bir marta 10 kiritilsa keyingi marta 100. Lekin >0 bulishi aniq. Xo'sh sizningcha kodda yozilgan algoritm umumiy nechta amal bajaradi? (count_if yane bunda 0 lar sonini hisoblaydi) Qanday turdagi…
Vector ni e'lon qilishda {} - figurali qavslar ishlatilgan.
Vector ustiga bosib kursak bu oddiy generic (template) sinf.
unda quyidagicha kod bor
Bunda vectorni {} ichidagi malumotlar bilan tuldirish konstruktori berilgan.
To'gri bu kod juda galati bulishi mumkin. Buni tushinish uchun shunchaki documentationi ochsa yetarli edi.
Umumiy qilsak vector ichida ikkita element bor {n va 0}
Kiruvchi malumotimiz n lekin bu uzunlik emas shuning uchun algoritm kiruvchi qiymatga boglanmagan
count_if esa n qanday bulishidan qatiy nazar doimo ikkita amal bajaradi.
yane amallar soni har doim const-o'zgarmas bu esa algoritmlar tilida O(1) deyiladi.
Vector ustiga bosib kursak bu oddiy generic (template) sinf.
unda quyidagicha kod bor
/**
* @brief Builds a %vector from an initializer list.
* @param __l An initializer_list.
* @param __a An allocator.
*
* Create a %vector consisting of copies of the elements in the
* initializer_list @a __l.
*
* This will call the element type's copy constructor N times
* (where N is @a __l.size()) and do no memory reallocation.
*/
_GLIBCXX20_CONSTEXPR
vector(initializer_list<value_type> __l,
const allocator_type& __a = allocator_type())
: _Base(__a)
{
_M_range_initialize(__l.begin(), __l.end(),
random_access_iterator_tag());
}
Bunda vectorni {} ichidagi malumotlar bilan tuldirish konstruktori berilgan.
To'gri bu kod juda galati bulishi mumkin. Buni tushinish uchun shunchaki documentationi ochsa yetarli edi.
Umumiy qilsak vector ichida ikkita element bor {n va 0}
Kiruvchi malumotimiz n lekin bu uzunlik emas shuning uchun algoritm kiruvchi qiymatga boglanmagan
count_if esa n qanday bulishidan qatiy nazar doimo ikkita amal bajaradi.
yane amallar soni har doim const-o'zgarmas bu esa algoritmlar tilida O(1) deyiladi.
👍8
Soatlar ajoib masala codeforcesdan
Telegraph
Mantiqiy muammo
Tassavur qiling oldizda bir nechta soat n-ta deb olsak. Soatlarning har birida bitta son (>0) sekund yozilgan. Har sekundda quyidagi amallar ketma ket bajariladi. 1. Barcha soatlardagi sonlar (sekundlar) birga kamayadi. Agar qaysidir soatdagi vaqt 0 ga teng…
⚡4
Bir nechi kundan biri hamma DeepSeek haqida gapirayotgandi. Men hatto etibor ham berganim yuq chunki uni GPTdan yaxshiroq javob berishiga to'grisi uncha ishonmagandim.
Bugun sinab kurdim to'grisini aytsam hayratda qoldirdi.
Sinab kurish uchun murakkabroq masala olishga harakat qildim.
GPT birdan xato yechim berdi.
DeepSeek 100 foiz yechmagan bulsada lekin juda chuqur harakat qildi.
Uzi bitta yechim berib yana ozgina uylab yuq bu yechmda mana bunday muammo bor deb boshqasiga birdan o'tib ketadi.
To'grisini aytsam haliyam o'zi bilan o'zi usha muammo ustida ishalaypti 😄
PS shunga xalaqit qilmay deb astagina GPT ga qaytdm
https://chat.deepseek.com
Bugun sinab kurdim to'grisini aytsam hayratda qoldirdi.
Sinab kurish uchun murakkabroq masala olishga harakat qildim.
GPT birdan xato yechim berdi.
DeepSeek 100 foiz yechmagan bulsada lekin juda chuqur harakat qildi.
Uzi bitta yechim berib yana ozgina uylab yuq bu yechmda mana bunday muammo bor deb boshqasiga birdan o'tib ketadi.
To'grisini aytsam haliyam o'zi bilan o'zi usha muammo ustida ishalaypti 😄
PS shunga xalaqit qilmay deb astagina GPT ga qaytdm
https://chat.deepseek.com
Deepseek
Chat with DeepSeek AI.
🤣8😁4🤡1
Algo Vision
Soatlar ajoib masala codeforcesdan
DeepSeek dan javob
Kecha odam ko'p so'rov berganiga balkim ishlamagndir lekin qoil juda chuqur tahlillab berdi.
Bu esa GPT o1 dan javob yechimdan ancha uzoq lekin uzbekchada
Kecha odam ko'p so'rov berganiga balkim ishlamagndir lekin qoil juda chuqur tahlillab berdi.
Bu esa GPT o1 dan javob yechimdan ancha uzoq lekin uzbekchada
⚡4
Tassavur qiling sizga 3^13 (3 sonini 13 darajasi) ni topish kerak bulsa faqat kalkulyatorsiz yoki tashqi yordamsz?
Xo'sh siz buni qanday usulda bajargan bular ediz?
Izohlarda fikringizni qoldiring
Imagine that you need to find 3^13 (Three to the power of thirteen) without using a calculator or any external help.
So, how would you solve it?
Xo'sh siz buni qanday usulda bajargan bular ediz?
Izohlarda fikringizni qoldiring
Imagine that you need to find 3^13 (Three to the power of thirteen) without using a calculator or any external help.
So, how would you solve it?
⚡7🆒1
Algo Vision
Tassavur qiling sizga 3^13 (3 sonini 13 darajasi) ni topish kerak bulsa faqat kalkulyatorsiz yoki tashqi yordamsz? Xo'sh siz buni qanday usulda bajargan bular ediz? Izohlarda fikringizni qoldiring Imagine that you need to find 3^13 (Three to the power of…
Bu haqida Xudo xohlasa shu hafta stream utkazamiz!!!.
Binary Pow in Action
Binary Pow in Action
❤🔥6🔥2
Qaysi vaqtda stream utkazish qulay? (Bu aniq Shanba yoki Yakshanba kuni buladi chunki shu kunlari bo'sh bulaman)
Anonymous Poll
20%
11:00
14%
13:00
20%
16:00
46%
17:00
Yandex dan juda ajoib imkoniyat sizda Open Source loyiha bormi?
unda tezda ruyxatdan o'ting va loyihangizga grant yutub olish imkoniyatini qulga kiriting
Yandex Grant OpenSource
Kutubxona, Framework .... model AI
faqatgina open source bo'lsa buldi va aniq bir yechimni uz ichiga olsa!
PS:600 mng rubl 12 ta saralangan loyihaga
unda tezda ruyxatdan o'ting va loyihangizga grant yutub olish imkoniyatini qulga kiriting
Yandex Grant OpenSource
Kutubxona, Framework .... model AI
faqatgina open source bo'lsa buldi va aniq bir yechimni uz ichiga olsa!
PS:600 mng rubl 12 ta saralangan loyihaga
opensource.yandex
Программа грантов Yandex Open Source
Поддерживаем внешние опенсорс-проекты независимыx разработчиков
👍7👌1