Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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++).
- Host: GitHub
- URL: https://github.com/yuvrajchandra/tipsntricks
- Owner: Yuvrajchandra
- Created: 2020-12-01T14:28:56.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-12T05:43:53.000Z (almost 4 years ago)
- Last Synced: 2023-10-19T23:59:39.014Z (about 1 year ago)
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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;
}
```---