Number of palindrome selfies
Sep 09, 2023 pm 08:37 PMA number is considered a "selfie number" if it can be represented using only its own digits and some mathematical operations.
For example, 936 is a selfie number.
$$\mathrm{936\:=\:(\sqrt{9})!^{3}\: \:6!\:=\:216\: \:720\:=\:No.936 chapter
You can see here that a series of operations are performed on the original number, and the result is equal to the original number.
The palindrome selfie number is a special selfie number. They satisfy the selfie multiplication rule.
Consider a number x.
Suppose the numerically reversed number of x is $\mathrm{x^\prime}$.
Let y be a number composed of the digits of x in different orders.
Suppose the number after the digital inversion of y is $\mathrm{y^\prime}$.
The number of palindromic selfies satisfies the following equation -
$$\mathrm{x\:×\:x^\prime\:=\:y\:×\:y^\prime}$$
Problem Statement
For a given number x, find its palindrome selfie number according to the selfie multiplication rule.
Example
Input: 1224 Output: 2142
illustrate -
Given x = 1224
So $\mathrm{x^\prime}$ = 4221 is obtained by reversing the number of x
Let y = 2142. y is formed using the digits of x in a different order
So $\mathrm{y^\prime}$ = 2412 is obtained by reversing the number of y
$\mathrm{x\:×\:x^\prime}$ = 1224 × 4221 = 5166504 and $\mathrm{y\:×\:y^\prime}$ = 2142 × 2412 = 5166504 p>
Sincex× x' = y × y', y is the number of palindrome selfies of x.
Input 4669: Output: 6496
illustrate -
Given x = 4669
So $\mathrm{x^\prime}$ = 9664 is obtained by reversing the number of x
Let y = 6496. y is formed using the digits of x in a different order
So $\mathrm{y^\prime}$ = 6946 is obtained by reversing the number of y
$\mathrm{x\:×\:x^\prime}$ = 4669 × 9664 = 45121216 and $\mathrm{y\:×\:y^\prime}$ = 6496× 6946= 45121216 p>
Since x× x' = y × y', y is the palindrome selfie number of x.
Input: 456 Output: No palindromic selfie number exists
illustrate -
Given x = 456
So $\mathrm{x^\prime}$ = 654 is obtained by reversing the number of x
Let y = 546. y is formed using the digits of x in a different order
So $\mathrm{y^\prime}$ = 645 is obtained by reversing the number of y
$\mathrm{x\:×\:x^\prime}$ = 456 × 654 = 298224 and $\mathrm{y\:×\:y^\prime}$ = 546× 645= 352170 p>
Since $\mathrm{x\:×\:x^\prime}$ ≠ $\mathrm{y\:×\:y^\prime}$, y is not the number of palindromic selfies of x. p>
No other permutation of 456 also satisfies the selfie multiplication rule.
solution
The solution to find the palindrome selfie number of a given number is quite intuitive and easy to understand.
The method includes the following steps -
Define a "reverse" function
Accepts an integer as input
Convert it to a string
Reverse string
Convert it back to an integer.
Define a function "Swap"
Taking integers i and j as input
Convert integer to string
Exchange the i-th and j-th characters in the string
Convert string back to integer.
Define a function "displacement"
Takes as input an integer, l, r, and a set of "permutations".
It recursively generates all possible permutations of integer numbers
It stores them in the "permutations" set.
Define a function "palindromic_selfie"
Takes an integer "num" and a set of "permutations" as input.
It uses the "permute" function to generate all possible permutations of the integer "num"
It then checks whether any of these permutations satisfy the palindromic selfie property by comparing the product of the number and its reverse order with the product of the permutation and its reverse order.
If such a permutation is found, the number is returned. Otherwise, -1 is returned.
In the main function, set a number "n" and an empty set to store the permutation.
Call the "palindromic_selfie" function with "n" and the empty set, and store the return result.
If the return result is -1, print "There is no palindrome selfie number". Otherwise, print the returned result.
Example: C program
The following C program finds the palindrome selfie number of a given integer (if one exists) and returns it. It does this by using the permute() function to find all possible permutations of a given number, and then using the reverse() function to determine whether the given number and any permutations of that number satisfy the selfie multiplication rules in the palindrome_selfie() function. If no such number exists, "No Palindrome Selfie Number Exists" is printed.
#include <bits/stdc++.h> using namespace std; // Function to reverse the digits of a number int reverse(int num){ // converting number to string string str = to_string(num); reverse(str.begin(), str.end()); // converting string to integer num = stoi(str); return num; } // Function that Swaps the digits i and j in the num int Swap(int num, int i, int j){ char temp; // converting number to string string s = to_string(num); // Swap the ith and jth character temp = s[i]; s[i] = s[j]; s[j] = temp; // Convert the string back to int and return return stoi(s); } // Function to get all possible permutations of the digits in num void permute(int num, int l, int r, set<int> &permutations){ // Adds the new permutation obtained in the set if (l == r) permutations.insert(num); else{ for (int i = l; i <= r; i++){ // Swap digits to get a different ordering int num_copy = Swap(num, l, i); // Recurse to next pair of digits permute(num_copy, l + 1, r, permutations); } } } // Function to check for palindrome selfie number int palindromic_selfie(int num, set<int>& permutations) { // Length of the number required for calculating all permutations of the digits int l = to_string(num).length() - 1; permute(num, 0, l, permutations); // Calculate all permutations //Remove the number and its reverse from the obtained set as this is the LHS of multiplicative equation auto n1 = permutations.find(reverse(num)); auto n2 = permutations.find(num); if (n1 != permutations.end()) permutations.erase(n1); if (n2 != permutations.end()) permutations.erase(n2); // Go through all other permutations of the number for (set<int>::iterator it = permutations.begin(); it != permutations.end(); it++) { int num2 = *it; // Check if selfie multiplicative rule holds i.e. x * reverse(x) = y * reverse(y) if (num * reverse(num) == num2 * reverse(num2)) { return num2; } } // If no such number found return -1; } int main(){ int n = 1234; cout << "n: " << n << endl; set<int> permutations; int ans = palindromic_selfie(n, permutations); if (ans == -1) { cout << "No Palindromic Selfie Number Exists" << endl; } else{ cout << ans << endl; } return 0; }
輸出
n: 1234 No Palindromic Selfie Number Exists
時間和空間復雜度分析
時間復雜度:O(n!)
此代碼的時間復雜度為 O(n!),其中 n 是輸入數字的位數。這是因為有 n! n 位數字的排列,并且 permute() 方法生成數字的所有潛在排列。
空間復雜度:O(n!)
由于集合“排列”包含所有可能的數字組合,等于 n!,因此該代碼的空間復雜度為 O(n!)。 verse() 和 Swap() 函數的空間復雜度為 O(n),因為它們還生成長度為 n 的臨時字符串。空間復雜度為 O(n!) 的排列集合主導了整個代碼的空間復雜度。
結論
Number of palindrome selfies是數學中一個有趣的概念。它們滿足自拍乘法方程。本文討論了一種方法來查找一個數字是否具有回文自拍號碼,如果是,則返回它。對問題的概念、解決方法、C++程序以及程序的時間和空間復雜度進行了深入分析。
The above is the detailed content of Number of palindrome selfies. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When chatting with friends on WeChat, we not only use words, but also often use various emoticons to better express emotions. Among them, WeChat selfie emoticons are a way of expression that many people like to use during chats. But sometimes, we may accidentally add some inappropriate selfie emoticons, and then we need to delete them. So how to delete it? This tutorial guide will give you a detailed introduction. For those who don’t know, come and follow this article to find out. How to delete selfie emoticons on WeChat? 1. First, you need to open WeChat and click on the settings icon on the emoticon store interface. 2. Then you need to click on my selfie emoticon on the My Emoticon interface. 3. Then click to enter my selfie expressions and select the organizing function. 4. Finally, check the ones that need to be deleted.

In 2025, global digital virtual currency trading platforms are fiercely competitive. This article authoritatively releases the top ten digital virtual currency trading platforms in the world in 2025 based on indicators such as transaction volume, security, and user experience. OKX ranks first with its strong technical strength and global operation strategy, and Binance follows closely with high liquidity and low fees. Platforms such as Gate.io, Coinbase, and Kraken are at the forefront with their respective advantages. The list covers trading platforms such as Huobi, KuCoin, Bitfinex, Crypto.com and Gemini, each with its own characteristics, but investment should be cautious. To choose a platform, you need to consider factors such as security, liquidity, fees, user experience, currency selection and regulatory compliance, and invest rationally

This article recommends ten digital currency trading apps: 1. OKX; 2. Binance; 3. Gate.io; 4. Huobi Global; 5. Kraken; 6. Coinbase; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Poloniex. When choosing a platform, you need to consider factors such as security, liquidity, transaction fees, currency selection, user interface, customer service support and regulatory compliance, and carefully evaluate risks and never blindly follow the trend.

Top 10 digital currency trading platforms: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini, these exchanges have their own characteristics, and users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

The best cryptocurrency trading and analysis platforms include: 1. OKX: the world's number one in trading volume, supports multiple transactions, provides AI market analysis and on-chain data monitoring. 2. Binance: The world's largest exchange, providing in-depth market conditions and new currency first-time offerings. 3. Sesame Open Door: Known for spot trading and OTC channels, it provides automated trading strategies. 4. CoinMarketCap: an authoritative market data platform, covering 20,000 currencies. 5. CoinGecko: Known for community sentiment analysis, it provides DeFi and NFT trend monitoring. 6. Non-small account: a domestic market platform, providing analysis of linkage between A-shares and currency markets. 7. On-chain Finance: Focus on blockchain news and update in-depth reports every day. 8. Golden Finance: 24 small

Reliable digital currency platforms include: 1. OKX, 2. Binance, 3. Gate.io, 4. Huobi Global, 5. Kraken, 6. Coinbase, 7. KuCoin, 8. Bitfinex, 9. Crypto.com, 10. Gemini. These exchanges have their own characteristics. Users can choose the platform that suits them based on factors such as security, fees, currency selection, user interface and customer support.

PrimeFactor?Innumbertheory,theprimefactorsofapositiveintegeraretheprimenumbersthatdividethatintegerexactly.Theprocessoffindingthesenumbersiscalledintegerfactorization,orprimefactorization.Example?Primefactorsof288are:288=2x2x2x2x2

Ranking of the top ten virtual currency trading platforms (latest in 2025): Binance: Global leader, high liquidity, and regulation has attracted attention. OKX: Large user base, supports multiple currencies, and provides leveraged trading. Gate.io: A senior exchange, with a variety of fiat currency payment methods, providing a variety of trading pairs and investment products. Bitget: Derivatives Exchange, high liquidity, low fees. Huobi: An old exchange that supports a variety of currencies and trading pairs. Coinbase: A well-known American exchange, strictly regulated. Phemex and so on.
