ashwanikumarsharma's blog

By ashwanikumarsharma, history, 2 days ago, In English

I was doing a Project Euler Problems, motivated by Radewoosh and aryanc403. I came across a problem that required finding the sum of the digits of a factorial. I still can't figure out how to implement it in C++ (there must be some way), but in Python, even a one-day beginner in coding can write this code easily. On one hand, Python makes our life easy, but on the other hand, it kills coding. There is literally no Integer Overflow. You can even do multiplication of a 100-digit number by another 100-digit number. Now I understand why some people do some specific problems in Python and the rest in C++ during Codeforces contests.

a = 1
for i in range(2, 101):
    a *= i

ans = 0
while a > 0:
    ans += (a % 10)
    a //= 10

print(ans)
»
2 days ago, # |
  Vote: I like it -11 Vote: I do not like it

Python is really good if you are starting out.

But for experienced Problem solvers, C++ is really good and Python kind of loses its value cause Python is really slow and the main reason people use Python for Competetive Programming is that it is easy to implement.

But for experienced Problem solvers, that doesn't matter.

  • »
    »
    2 days ago, # ^ |
      Vote: I like it -8 Vote: I do not like it

    agree, for me whenever i encounter TLE, i just optimize it to cpp using claude nowadays lol. IRL i would probably delegate computationally expensive operations using CFFI.

  • »
    »
    45 hours ago, # ^ |
      Vote: I like it -8 Vote: I do not like it

    python for A B C, faster language for D+

»
2 days ago, # |
  Vote: I like it +8 Vote: I do not like it

python lacks many data structure needed for algorithms like dijkstra so it is only benefitcial for some problems that has the potential to overflow so it doesnt kills coding for sure

  • »
    »
    2 days ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    u can use heapq.heapify, i think someone made a cp library w/ python years ago called PyRival, check it out.

    • »
      »
      »
      2 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      thanks dude, didn't know this

    • »
      »
      »
      45 hours ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      Yes. heappq implements a min-heap by default. I have used it in some leetcode problems. heapq can be used as priority queue. It is very handy when we need to store pairs or triplets in priority queue!

»
40 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I use python since it is the only programing language that I know. Not experienced issues with speed yet but then again I am only newbie.