Блог пользователя ashwanikumarsharma

Автор ashwanikumarsharma, история, 2 дня назад, По-английски

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)
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
2 дня назад, # |
  Проголосовать: нравится -11 Проголосовать: не нравится

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 дня назад, # ^ |
      Проголосовать: нравится -8 Проголосовать: не нравится

    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.

  • »
    »
    47 часов назад, # ^ |
      Проголосовать: нравится -8 Проголосовать: не нравится

    python for A B C, faster language for D+

»
2 дня назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

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 дня назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

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

    • »
      »
      »
      2 дня назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      thanks dude, didn't know this

    • »
      »
      »
      47 часов назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      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!

»
42 часа назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.