Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
¿Cómo manejar "((9^x)-2)%5" sin desbordamiento en x más alto?

Estoy preparando un examen para mi curso de matemáticas discretas y tengo que implementar la función

f(x) = ((9^x)-2)%5

Dado que los valores de nuestra x en la tarea son 100000 < x <= 1000000, tengo algunos problemas para manejar el desbordamiento

En nuestra tarea hay una pista: "Encuentre una manera de aplicar el módulo a lo largo de los cálculos. De lo contrario, obtendrá números demasiado grandes muy rápidamente al calcular 9^x".

No puedo descifrar la lógica para hacer que esto funcione aunque, cualquier ayuda sería apreciada

 /* This function should return 1 if 9^x-2 mod 5 = 2 and 0 otherwise */ int is2mod5(int x){ int a; double b = pow(9, x); a = b; int c = (a-2)%5; if (c == 2) { return 1; } else { return 0; } }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Dado que está calculando el módulo 5, las multiplicaciones también se pueden hacer en el módulo 5. 9 es congruente con -1 módulo 5. Así 9^x es congruente con (-1)^x módulo 5, es decir, 1 si x es par y -1 si x es impar. Restar 2 da -1 y -3 que son congruentes con 4 y 2 respectivamente.

Así, f(x) es 4 si x es par y 2 si x es impar.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!