The fox saves the chrome by the fox saves by itself. Cant fly from land but not fly from the water. Furthermore, the fox cant swim. The fox is four times faster than the duck. It is possible that it is possible to reach the distance from the ground.
In front of you are three boxes. One contains only apples, one contains only a mix of apples and oranges. Each box is incorrectly labeled, like this:
Box 1: “apples”
Box 2: “oranges”
Box 3: “apples & oranges”
Question: You get to choose one, and one box only. It will remove your skin from the box. After that, you will be able to relabel all three boxes.
The integers without the multiplication operation. O (log (n) or better)
Write a function that returns the nth prime number. For example, nthPrime (1) should return 2, since this is the first prime number, nthPrime (2) should return 3, and so on.
It is not necessary to set the number of digits for the digits, and it is “not possible”.
Ex:
N = "218765" => "251678"
N = "1234" => "1243"
N = "4321" => "Not Possible"
N = "534976" => "536479"
#include<stdio.h> /* function to multiply two numbers x and y*/ int multiply(int x, int y) { /* 0 multiplied with anything gives 0 */ if(y == 0) return 0; /* Add x one by one */ if(y > 0 ) return (x + multiply(x, y-1)); /* the case where y is negative */ if(y < 0 ) return -multiply(x, -y); } int main() { printf("\n %d", multiply(5, -11)); getchar(); return 0; }
#include <stdio.h> #include <stdlib.h> #include <math.h> #define MAX 100000000 void prime(int n, int *primes) { int i,j,count=0; primes[count++] = 2; if (count == n) return; for(i=3;i<=MAX;i+=2) { int isPrime=1; int jMax = sqrt(i); for(j=3;j<=jMax;j+=2) { if(i%j==0) { isPrime=0; break; } } if(isPrime) { primes[count++] = i; if(count==n) return; } } } int main() { int n,i; scanf("%d",&n); int arr[n]; int maxPrime = 0; for(i=0;i<n;i++) { scanf("%d",&arr[i]); if (arr[i] > maxPrime) maxPrime = arr[i]; } int primes[maxPrime]; prime(maxPrime, primes); for (i=0;i<n;i++) { printf("%d\n", primes[arr[i]-1]); } return 0;
#include <iostream> #include <cstring> #include <algorithm> using namespace std; // Utility function to swap two digits void swap(char *a, char *b) { char temp = *a; *a = *b; *b = temp; } // Given a number as a char array number[], this function finds the // next greater number. It modifies the same array to store the result void findNext(char number[], int n) { int i, j; // I) Start from the right most digit and find the first digit that is // smaller than the digit next to it. for (i = n-1; i > 0; i--) if (number[i] > number[i-1]) break; // If no such digit is found, then all digits are in descending order // means there cannot be a greater number with same set of digits if (i==0) { cout << "Next number is not possible"; return; } // II) Find the smallest digit on right side of (i-1)'th digit that is // greater than number[i-1] int x = number[i-1], smallest = i; for (j = i+1; j < n; j++) if (number[j] > x && number[j] < number[smallest]) smallest = j; // III) Swap the above found smallest digit with number[i-1] swap(&number[smallest], &number[i-1]); // IV) Sort the digits after (i-1) in ascending order sort(number + i, number + n); cout << "Next number with same set of digits is " << number; return; } // Driver program to test above function int main() { char digits[] = "534976"; int n = strlen(digits); findNext(digits, n); return 0; }
Source: https://habr.com/ru/post/346424/
All Articles