Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yuvrajchandra/tipsntricks

This repository includes various tips and tricks to solve different Coding Questions (in C++).
https://github.com/yuvrajchandra/tipsntricks

Last synced: 2 days ago
JSON representation

This repository includes various tips and tricks to solve different Coding Questions (in C++).

Awesome Lists containing this project

README

        

# TipsNTricks
This repository includes various tips and tricks to solve different Coding Questions (in C++).

---

+ ### To intialise a vector with given size and value.
For eg- Intialize a vector of size 5 and value of all elements as 0.
**Syntax :**
```
vector vector1(size, value);
```

```
vector vector1(5, 0);
```

---

+ ### To insert a map with digits as key and frequency of digits as value
```
unordered_map result;
for(int i=0; i 10^6)
We can use Kamenetsky’s formula to find our answer !

It approximates the number of digits in a factorial by :
f(x) = log10( ((n/e)^n) * sqrt(2 * pi * n))

Thus, we can pretty easily use the property of logarithms to,
f(x) = n * log10(( n/ e)) + log10(2 * pi * n)/2

```
long long findDigits(int n)
{
if (n < 0)
return 0;
if (n <= 1)
return 1;

// Use Kamenetsky formula to calculate the number of digits
double x = ((n * log10(n / M_E) + log10(2 * M_PI * n) / 2.0));

return floor(x) + 1;
}
```

---