
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Find the value of the function Y = (X^6 + X^2 + 9894845) % 981 in C++
Suppose we have given function like f(x) = (x^6 + x^2 + 9894845) % 971, now for a given value of x, we have to find the value of f(x).
So, if the input is like 5, then the output will be 469
To solve this, we will follow these steps −
Define a function power_mod(), this will take base, exponent, modulus,
base := base mod modulus
result := 1
while exponent > 0, do −
if exponent is odd, then −
result := (result * base) mod modulus
base := (base * base) mod modulus
exponent = exponent /2
return result
From the main method do the following −
return power_mod(n, 6, m)+power_mod(n, 2, m)) mod m + 355) mod m
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; typedef long long int lli; lli power_mod(lli base, lli exponent, lli modulus) { base %= modulus; lli result = 1; while (exponent > 0) { if (exponent & 1) result = (result * base) % modulus; base = (base * base) % modulus; exponent >>= 1; } return result; } int main(){ lli n = 654654, m = 971; cout<<(((power_mod(n, 6, m)+power_mod(n, 2, m))% m + 355)% m); }
Input
84562
Output
450
- Related Articles
- The reduced form of $36 x^{2}-81 y^{2}$ isi$(6 x+9 y)(6 x-9 y) $ii$(6 x+9 y)(4 x-5) $iii.$(9 x+6 y)(9 x-6 y)$iv. $(9 y-6 x)(9 y+6 x) $
- Find the value of$3 x^{2}-2 y^{2}$if x=-2 and y=2
- Multiply:$(x^6-y^6)$ by $(x^2+y^2)$
- Find the value of x and verify$8 x - 14 = - 2 x + 6$
- Draw the graph of the function y = 5x. From the graph, find the value of y when x = 6.
- Given $(x^{2}+y^{2})$=74 and xy =35, find the value of:a) x+yb) x-y
- If $x=1,\ y=2$ and $z=5$, find the value of $x^{2}+y^{2}+z^{2}$.
- Factorize:\( x^{3}-2 x^{2} y+3 x y^{2}-6 y^{3} \)
- Simplify:\( 4(x+y)-6(x+y)^{2} \)
- Find the products of the following monomials.a. \( (-6) x^{2} \times 7 x y \)b. \( 2 a b \times(-6) a b \)c. \( \left(-4 x^{2} y^{2}\right) \times 3 x^{2} y^{2} \)d. \( 9 x y z \times 2 z^{3} \)
- Find the value using suitable identity$( x-y^2 )^2$
- Find the value of the following using suitable properties(a) \( (3 x+4 y)^{2} \)(b) \( (0.2 x-0.3 y)^{2} \)(c) \( (x+3)(x-5) \)(d) \( \left(x-y^{2}\right)^{2} \)
- If \( 2 x+y=23 \) and \( 4 x-y=19 \), find the values of \( 5 y-2 x \) and \( \frac{y}{x}-2 \).
- Find the mean of $x, x + 2, x + 4, x + 6, x + 8$.
- Find the value of \( k \), if \( x=2, y=1 \) is a solution of the equation \( 2 x+3 y=k \)

Advertisements