Encuentre N valores de X1, X2, … Xn tales que X1 < X2 < … < XN y sin(X1) < sin(X2) < … < sin(XN)

Dado un número N , la tarea es encontrar los N valores enteros de X i tales que X 1 < X 2 < … < X N y sin(X 1 ) < sin(X 2 ) < … < sin(X N ) .
Ejemplos: 
 

Entrada: N = 5 
Salida: 
X1 = 0 sen(X1) = 0,000000 
X2 = 710 sen(X2) = 0,000060 
X3 = 1420 sen(X3) = 0,000121 
X4 = 2130 sen(X4) = 0,000181 
X5 = 2840 sen(X5) = 0,000241
Entrada: N = 3 
Salida: 
X1 = 0 sen(X1) = 0,000000 
X2 = 710 sen(X2) = 0,000060 
X3 = 1420 sen(X3) = 0,000121 
 

Enfoque: La idea es utilizar el valor fraccionario de PI(&PI); es decir, Pi = 355/113 dado que dio el mejor valor racional de PI con una precisión de 0,000009%. 
 

As,
   PI = 355/113
=> 113*PI = 355
=> 2*(113*PI) = 710

As sin() function has a period of 2*PI,
Therefore sin(2*k*PI + Y) = sin(Y);

Según la ecuación anterior para obtener el valor X 1 < X 2 < … < X N y sin(X 1 ) < sin(X 2 ) < … < sin(X N ) debemos encontrar el valor de sin(X) con un incremento de 710.
A continuación se muestra la implementación del enfoque anterior: 
 

C++

// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
 
// Function to print all such Xi s.t.
// all Xi and sin(Xi) are strictly
// increasing
void printSinX(int N)
{
    int Xi = 0;
    int num = 1;
 
    // Till N becomes zero
    while (N--) {
 
        cout << "X" << num << " = " << Xi;
        cout << " sin(X" << num << ") = "
             << fixed;
 
        // Find the value of sin() using
        // inbuilt function
        cout << setprecision(6)
             << sin(Xi) << endl;
 
        num += 1;
 
        // increment by 710
        Xi += 710;
    }
}
 
// Driver Code
int main()
{
    int N = 5;
 
    // Function Call
    printSinX(N);
    return 0;
}

Java

// Java program for the above approach
import java.util.*;
 
class GFG{
 
// Function to print all such Xi s.t.
// all Xi and sin(Xi) are strictly
// increasing
static void printSinX(int N)
{
    int Xi = 0;
    int num = 1;
 
    // Till N becomes zero
    while (N-- > 0)
    {
 
        System.out.print("X" + num + " = " + Xi);
        System.out.print(" sin(X" + num + ") = ");
 
        // Find the value of sin() using
        // inbuilt function
        System.out.printf("%.6f", Math.sin(Xi));
        System.out.println();
        num += 1;
 
        // Increment by 710
        Xi += 710;
    }
}
 
// Driver Code
public static void main(String[] args)
{
    int N = 5;
 
    // Function Call
    printSinX(N);
}
}
 
// This code is contributed by Princi Singh

Python3

# Python3 program for the above approach
import math
 
# Function to print all such Xi s.t.
# all Xi and sin(Xi) are strictly
# increasing
def printSinX(N):
 
    Xi = 0;
    num = 1;
 
    # Till N becomes zero
    while (N > 0):
 
        print("X", num, "=", Xi, end = " ");
        print("sin(X", num, ") =", end = " ");
 
        # Find the value of sin() using
        # inbuilt function
        print("{:.6f}".format(math.sin(Xi)), "\n");
 
        num += 1;
 
        # increment by 710
        Xi += 710;
        N = N - 1;
 
# Driver Code
N = 5;
 
# Function Call
printSinX(N)
 
# This code is contributed by Code_Mech

C#

// C# program for the above approach
using System;
 
class GFG{
 
// Function to print all such Xi s.t.
// all Xi and sin(Xi) are strictly
// increasing
static void printSinX(int N)
{
    int Xi = 0;
    int num = 1;
 
    // Till N becomes zero
    while (N-- > 0)
    {
        Console.Write("X" + num + " = " + Xi);
        Console.Write(" sin(X" + num + ") = ");
 
        // Find the value of sin() using
        // inbuilt function
        Console.Write("{0:F6}", Math.Sin(Xi));
        Console.WriteLine();
        num += 1;
 
        // Increment by 710
        Xi += 710;
    }
}
 
// Driver Code
public static void Main(String[] args)
{
    int N = 5;
 
    // Function Call
    printSinX(N);
}
}
 
// This code is contributed by SoumikMondal

Javascript

<script>
 
// Javascript program for the above approach
  
// Function to print all such Xi s.t.
// all Xi and sin(Xi) are strictly
// increasing
function printSinX(N)
{
    let Xi = 0;
    let num = 1;
   
    // Till N becomes zero
    while (N-- > 0)
    {
   
        document.write("X" + num + " = " + Xi);
        document.write(" sin(X" + num + ") = ");
   
        // Find the value of sin() using
        // inbuilt function
        document.write(Math.sin(Xi).toFixed(6));
        document.write("<br/>");
        num += 1;
   
        // Increment by 710
        Xi += 710;
    }
}
   
 
// Driver Code
     
    let N = 5;
   
    // Function Call
    printSinX(N);
                   
</script>
Producción: 

X1 = 0 sin(X1) = 0.000000
X2 = 710 sin(X2) = 0.000060
X3 = 1420 sin(X3) = 0.000121
X4 = 2130 sin(X4) = 0.000181
X5 = 2840 sin(X5) = 0.000241

 

Complejidad de tiempo: O(N)

Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por ssatyanand7 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *