Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 0

robatter/Java

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (5)
master
Development
revert-1432-revert-1429-Development
revert-1429-Development
nikhilkala-patch-1
master
Branches (5)
master
Development
revert-1432-revert-1429-Development
revert-1429-Development
nikhilkala-patch-1
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (5)
master
Development
revert-1432-revert-1429-Development
revert-1429-Development
nikhilkala-patch-1
Java
/
Maths
/
VampireNumber.java
Java
/
Maths
/
VampireNumber.java
VampireNumber.java 2.40 KB
Copy Edit Raw Blame History
Stepfen Shawn authored 2020年05月13日 06:01 +08:00 . Update VampireNumber.java
package Maths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
n number theory, a vampire number (or true vampire number) is a composite natural number with an even number of digits,
that can be factored into two natural numbers each with half as many digits as the original number
and not both with trailing zeroes, where the two factors contain precisely
all the digits of the original number, in any order, counting multiplicity.
The first vampire number is 1260 = 21 ×ばつ 60.
* *
* <p>
* * link: https://en.wikipedia.org/wiki/Vampire_number
* * </p>
* <p>
*
*/
public class VampireNumber {
public static void main(String[] args) {
test(10,1000);
}
static void test(int startValue, int stopValue) {
int countofRes = 1;
StringBuilder res = new StringBuilder();
for (int i = startValue; i <= stopValue; i++) {
for (int j = i; j <= stopValue; j++) {
// System.out.println(i+ " "+ j);
if (isVampireNumber(i, j,true)) {
countofRes++;
res.append("" + countofRes + ": = ( " + i + "," + j + " = " + i*j + ")" + "\n");
}
}
}
System.out.println(res);
}
static boolean isVampireNumber(int a, int b, boolean noPseudoVamireNumbers ) {
// this is for pseudoVampireNumbers pseudovampire number need not be of length n/2 digits for example
// 126 = 6 x 21
if (noPseudoVamireNumbers) {
if (a * 10 <= b || b * 10 <= a) {
return false;
}
}
String mulDigits = splitIntoDigits(a*b,0);
String faktorDigits = splitIntoDigits(a,b);
return mulDigits.equals(faktorDigits);
}
// methode to Split the numbers to Digits
static String splitIntoDigits(int num, int num2) {
StringBuilder res = new StringBuilder();
ArrayList<Integer> digits = new ArrayList<>();
while (num > 0) {
digits.add(num%10);
num /= 10;
}
while (num2 > 0) {
digits.add(num2%10);
num2/= 10;
}
Collections.sort(digits);
for (int i : digits) {
res.append(i);
}
return res.toString();
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

All Algorithms implemented in Java
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/robatter/Java.git
git@gitee.com:robatter/Java.git
robatter
Java
Java
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /