18
社区成员




美国数学家维纳(N.Wiener)智力早熟,11岁就上了大学。他曾在1935~1936年应邀来中国清华大学讲学。
一次,他参加某个重要会议,年轻的脸孔引人注目。于是有人询问他的年龄,他回答说:“我年龄的立方是个4位数。我年龄的4次方是个6位数。这10个数字正好包含了从0到9这10个数字,每个都恰好出现1次。”
请你推算一下,他当时到底有多年轻。
提示:
先用/10和%10把各个位上的数取出来,然后判断是否相等
public class WienerAge {
public static void main(String[] args) {
for (int age = 10; age < 100; age++) {
int cube = age * age * age;
int fourth = cube * age;
int[] digitsCube = new int[10];
int[] digitsFourth = new int[10];
// 填充年龄立方的数字计数数组
for (int num = cube; num > 0; num /= 10) {
digitsCube[num % 10]++;
}
// 填充年龄四次方的数字计数数组
for (int num = fourth; num > 0; num /= 10) {
digitsFourth[num % 10]++;
}
// 检查是否每个数字都恰好出现一次
boolean allUnique = true;
for (int i = 0; i < 10; i++) {
if ((digitsCube[i] + digitsFourth[i]) != 1) {
allUnique = false;
break;
}
}
if (allUnique) {
System.out.println("维纳的年龄是: " + age);
break;
}
}
}
}
新手学算法,不要嘲笑我/(ㄒoㄒ)/~~
public class Test_12 {
public static void main(String[] args) {
age();
}
private static void age() {
Set<Integer> set = new HashSet<>();
for (int age = 0; age <= 100; age++) {
set.clear();
int age3 = age * age * age;
int age4 = age3 * age;
if ((age3 >= 1000 && age3 <= 9999) && (age4 >= 100000 && age4 <= 999999)) {
while (age3 > 0) {
set.add(age3 % 10);
age3 = age3 / 10;
}
while (age4 > 0) {
set.add(age4 % 10);
age4 = age4 / 10;
}
if (set.size() == 10) {
System.out.println(age);
}
}
}
}
}
#include <stdio.h>
int main()
{
int a;
for (int i = 18; i < 22; i++)
{
a = i*i*i+i*i*i*i*10000;
printf("%d\n", a);
}
return 0;
}
#include <stdio.h>
int main()
{
int age;
for (age = 0; age<=100; age++)
{
int age3 = age*age*age;
if (age3 < 1000 || age3 > 9999)
continue;
int age4 = age*age*age*age;
if (age4 < 100000 || age4 > 999999)
continue;
int a[10];
for (int i = 0; i < 4; i++)
{
a[i] = age3%10;
age3 = age3/10;
}
for (int i = 0; i < 6; i++)
{
a[i+4] = age4%10;
age4 = age4/10;
}
int count = 0;
for (int i = 0; i < 10; i++)
{
for (int j = i+1; j < 10; j++)
{
if (a[i] == a[j])
count++;
}
}
if (count == 0)
{
printf("age:%d", age);
break;
}
}
return 0;
}
public class GuessAge {
static int arr[]=new int[10];
public static void main(String[] args) {
int l,s,t,count;
boolean b;
for(int i=11;i<=50;i++) {
b=true;
l=i*i*i;
s=i*i*i*i;
count=0;
while(l>0) {
t=l%10;
arr[count]=t;
count++;
l/=10;
}
while(s>0) {
t=s%10;
arr[count]=t;
count++;
s/=10;
}
for(int j=0;j<10;j++) {
for(int k=0;k<10;k++) {
if(j==k) {
continue;
}
if(arr[j]==arr[k]) {
b=false;
}
}
}
for(int j=0;j<arr.length;j++) {
arr[j]=0;
}
if(b) {
System.out.println(i);
break;
}
}
}
}
@org.junit.Test
public void testAge(){
for(int age = 11;age <= 100;age++) {
boolean isAge = isAge(age);
if (isAge){
System.out.println("age = " + age);
}
}
}
private boolean isAge(int age){
int a3 = age * age * age;
int a4= a3 * age;
String a3S =Integer.toString(a3);
String a4S =Integer.toString(a4);
if (a3S.length() != 4 || a4S.length() != 6){
return false;
}
char[] chars = new StringBuilder(a3S).append(a4S).toString().toCharArray();
boolean isAge = true;
Set set = new HashSet();
for (char c : chars){
if (!set.add(c)){// 0,1,2,3,4,5,6,7,8,9
isAge = false;
break;
}
}
return isAge;
}
#include <iostream>
using namespace std;
#include <math.h>
void calculate()
{
int number[10];
int ages=0;
int min,max;
while(ages<100)
{
min=pow(ages,3);
max=pow(ages,4);
if((min>=1e3&&min<1e4)&&(max>=1e5&&max<1e6))
{
for(int i=0; i<4; i++)
{
number[i]=min%10;
min/=10;
}
for(int i=4; i<10; i++)
{
number[i]=max%10;
max/=10;
}
int i=0,j=1;
int test=1;
while(i<9)
{
if(number[i]==number[j])
{
test=0;
break;
}
if(j==9)
{
i++;
j=i;
}
j++;
}
cout<<test;
if(test==1)
{
cout<<"维纳的年龄为: "<<ages<<endl;
break;
}
}
ages++;
}
}
int main()
{
calculate();
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
bool isnl(long long x)
{
long long y = x * x * x;
if (y < 1000 || y>9999)
return 0;
long long u = y * x;
if (u < 100000 || u>999999)
return 0;
vector <long long> h;
while (!(y == 0))
{
long long j = y % 10;
for (auto a :h)
{
if (j == a)
return 0;
}
h.push_back(j);
y /= 10;
}
while (!(u == 0))
{
long long j = u % 10;
for (auto a : h)
{
if (j == a)
return 0;
}
h.push_back(j);
u /= 10;
}
return 1;
}
int main()
{
for (long long i = 10; i < 30; i++)
{
if (isnl(i))
cout << i;
}
return 0;
}
package Primary;
public class CaiNianling {
public static void main(String args[]) {
for(int age=18;age<=21;age++) {
int a=age*age*age;
int b=a*age;
String a1=Integer.toString(a);
String b1=Integer.toString(b);
boolean f=a1.length()==4;
boolean f0=b1.length()==6;
boolean f1=a1.contains("1")||b1.contains("1");
boolean f2=a1.contains("2")||b1.contains("2");
boolean f3=a1.contains("3")||b1.contains("3");
boolean f4=a1.contains("4")||b1.contains("4");
boolean f5=a1.contains("5")||b1.contains("5");
boolean f6=a1.contains("6")||b1.contains("6");
boolean f7=a1.contains("7")||b1.contains("7");
boolean f8=a1.contains("8")||b1.contains("8");
boolean f9=a1.contains("9")||b1.contains("9");
boolean f10=a1.contains("0")||b1.contains("0");
if(f&&f0&&f1&&f2&&f3&&f4&&f5&&f6&&f7&&f8&&f9&&f10) {
System.out.println(age);
}
}
}
}
#include"bits/stdc++.h"
using namespace std;
int arr[]{0,1,2,3,4,5,6,7,8,9};
int main(void){
int x,flag;
for(x = 1;x <= 190;x++){
int a4 = pow(x,3), a6 = pow(x,4);
flag = 1;
if(a4 >= 1000 and a4 <= 9999 and a6 >= 100000 and a6 <= 999999){
int a4_t = a4;
while(a4_t){
for(int i = 0;i < 10;i++){
if((a4_t % 10) == arr[i]) arr[i] = -1;
}a4_t /= 10;
}
int a6_t = a6;
while(a6_t){
for(int i = 0;i < 10;i++){
if((a6_t % 10) == arr[i]) arr[i] = -1;
}a6_t /= 10;
}
// 判断是否全是-1
for(int i = 0;i < 10;i++){
if(*(arr + i) != -1){
flag = 0;
for(int j = 0;j < 10;j++){
arr[j] = j;
}
break;
}
}
if(flag == 1){
cout << x << endl;
for(int j = 0;j < 10;j++){ // 检测到全是flag=1 再把数组赋值回去 检测下一个循环
arr[j] = j;
}
}
}
}
// cout << pow(18,3) << " " << pow(18,4) << endl;
// cout << pow(19,3) << " " << pow(19,4) << endl;
// cout << pow(20,3) << " " << pow(20,4) << endl;
// cout << pow(21,3) << " " << pow(21,4) << endl;
return 0;
}
#include<stdio.h>
int Bool(int a,int b)
{
if(a/1000>0&&b/100000>0)
{
return 1;
}else{
return 0;
}
}
int Bool2(int a,int b)
{
int temp[20];
int i=0;
while(a!=0)
{
temp[i++]=a%10;
a=a/10;
}
while(b!=0)
{
temp[i++]=b%10;
b=b/10;
}
int k=0;
int j=0;
for(j=0;j<10-1;j++){
for(i=j+1;i<10;i++){
if(temp[j]==temp[i]){
return 0;
}
}
}
return 1;
}
int main()
{
int a,b,k;
for(int i=1;i<100;i++)
{
a=iii;
b=iii*i;
k=i;
if(Bool(a,b)&&Bool2(a,b))
{
printf("%d ",k);
}
}
return 0;
}
#include <stdio.h>
int main()
{
int i,j,t,f,flag=0;
int a[10]={0,1,2,3,4,5,6,7,8,9};
for(i=1;i<=100;i++)
{
t=i*i*i;
f=i*i*i*i;
if(t>=1000&&f>=100000)
{
while(t)
{
for(j=0;j<10;j++)
{
if(a[j]==t%10) a[j]=-1;
}
t/=10;
}
while(f)
{
for(j=0;j<10;j++)
{
if(a[j]==f%10) a[j]=-1;
}
f/=10;
}
for(j=0;j<10;j++)
{
if(a[j]==-1) flag=1;
else
{flag=0;
break;
}
}
if(flag==1)
{
printf("%d",i);
break;
}
else
{
a[0]=0;
for(j=1;j<10;j++)
a[j]=a[j-1]+1;
}
}
}
return 0;
}
public static void main(String[] args) {
int[] arr=new int[10];
for(int i=1;i<100;i++)
{
int j=0,cnt=0;
int p3=(int)Math.pow(i,3),p4=(int)Math.pow(i,4);
if(getnum(p3)==4&&getnum(p4)==6)
{
while(p4!=0)
{
arr[j++]=p4%10;
p4/=10;
}
while(p3!=0)
{
arr[j++]=p3%10;
p3/=10;
}
Arrays.sort(arr);
for(int c:arr)
{
if(c!=cnt)
break;
cnt++;
}
if(cnt==10)
System.out.println(i);
}
}
}
public static int getnum(int n)
{
int count=0;
while(n!=0)
{
count++;
n/=10;
}
return count;
}
std::vector<int> num;
bool is_the_num = true;
for (int i = 0; i <= std::pow(9999, 1.0/3); i++) {
num.clear();
num.resize(10);
int A = i * i * i;
int B = A * i;
num[A%10]++;
num[A/10 % 10]++;
num[A/100 %10]++;
num[A/1000%10]++;
num[B%10]++;
num[B/10 %10]++;
num[B/100 %10] ++;
num[B/1000 %10]++;
num[B/10000%10]++;
num[B/100000%10]++;
for (int j=0; j<10; j++) {
if (num[j] > 1) {
is_the_num = false;
}
}
if (is_the_num) {
std::cout << "age num is : " << i << std::endl;
break;
}
is_the_num = true;
}
#include
using namespace std;
constexpr auto N = 120;
int main()
{
for (int i = 0; i <= N; i++)
{
int A = i * i*i;
int B = i * i*i*i;
//cout << A << B << endl;
int b[10] = { 0,1,2,3,4,5,6,7,8,9 };
int a[11];
{
a[0] = (A /1)% 10;
a[1] = (A / 10) % 10;
a[2] = (A / 100) % 10;
a[3] = (A / 1000)%10;
a[4] = (B/1) % 10;
a[5] = (B / 10) % 10;
a[6] = (B / 100) % 10;
a[7] = (B / 1000) % 10;
a[8] = (B / 10000) % 10;
a[9] = (B / 100000)%10;
a[10] = i;
}
for (int i = 0; i <11; i++) {
for (int j = 0; j <11 - 1 - i; j++) {
if (a[j] > a[j + 1]) { // 相邻元素两两对比
int temp = a[j + 1]; // 元素交换
a[j + 1] = a[j];
a[j] = temp;
}
}
}
int num = 0;
for (int i = 0; i < 10; i++)
{
if (a[i] == b[i])
num++;
if (num ==10)
{
cout << a[10] << endl;
cout << num;
}
}
}
system("pause");
return 0;
}
void Age()
{
for (int i = 0; i < 50; i++)
{
double li = Math.Pow(i,3);
double sici = Math.Pow(i,4);
var liString = string.Format("{0}{1}", li.ToString(), sici.ToString());
if (liString.Length == 10)
{
if (DuplicateRemoval(liString))
{
Debug.LogError("年龄:" + i);
}
}
}
}
private bool DuplicateRemoval(string liString)
{
bool[] bools = new[] {false, false, false, false, false, false, false, false, false, false};
for (int i = 0; i < liString.Length; i++)
{
var num = liString.Substring(i, 1);
if (!bools[int.Parse(num)])
{
bools[int.Parse(num)] = true;
}
else
{
return false;
}
}
return true;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int age;
for(age=10;age<32;++age)
{
int num1=(int)pow(age,3),num2=(int)pow(age,4);
int count[10]={0};
while(num1>0)
{
count[num1%10]++;
num1/=10;
}
while(num2>0)
{
count[num2%10]++;
num2/=10;
}
int i;
for(i=0;i<10;++i)
{
if(count[i]!=1)
break;
else if(i==9)
cout<<age<<endl;
}
}
return 0;
}
for (let i = 0; i < 100; i++) {
if (i * i * i < 10000 && i * i * i > 999) {
if (i * i * i * i < 1000000 && i * i * i * i > 99999) {
let str = (i * i * i).toString() + (i * i * i * i).toString()
if (str.indexOf('0') >= 0
&& str.indexOf('1') >= 0
&& str.indexOf('2') >= 0
&& str.indexOf('3') >= 0
&& str.indexOf('4') >= 0
&& str.indexOf('5') >= 0
&& str.indexOf('6') >= 0
&& str.indexOf('7') >= 0
&& str.indexOf('8') >= 0
&& str.indexOf('9') >= 0) {
console.log(i);
}
}
}
}