5

「最後の桁を最初の桁に移動」の意味: 12345 --> 51234

答えがあるに違いないと誰かが言う。とても単純なはずだと思ったのですが、コーディングしてもXが見つかりません。誰か助けて?

public static void main(String[] args) {
    for(int i=10; s<99999; i++){
        if(2*i==convertInt(i)){
            System.out.println(i);
        }
    }
}

private static int convertInt(int i) {
    String s = i+"";
    int index = s.length()-1;
    String newS = s.charAt(index) + s.substring(0, index);
    return Integer.parseInt(newS);
}
4

4 に答える 4

8

私はこの機能を使用しました:

public static boolean isMultiple(int x) {
    String g = String.valueOf(x);
    g = g.substring(g.length()-1) + g.substring(0, g.length()-1);
    int y = Integer.parseInt(g);
    if(y == x * 2) return true;
    return false;
}

このループでは:

int x = 10;
while(!isMultiple(x)) {
    System.out.println(x + ", " + isMultiple(x));
    x++;
}

そして、6億5000万までの真価は得ていません。これは絶対にありえないと強く思います。私の推測では、これで機能する数値はありませんが、これを実行したままにします。見つけたら編集します。

編集:このような数字があるようです。上記を参照。

于 2012-12-31T20:17:43.183 に答える
3

http://answers.yahoo.com/question/index?qid=20080207083949AAoBkqv

Let's start with the number without the two. Call it n.

If you multiply this by 10 and add 2 you would have your first number:
10n + 2

Doubling this you'd have:
20n + 4

This should be equivalent to taking n and putting a two in the front.
n + 2 * 10^d

Here d represents the number of digits.
20n + 4 = n + 2* 10^d

19n + 4 = 2 * 10^d
n = (2 * 10^d - 4) / 19

If you try values of d = 1, 2, 3, etc. you eventually get to n = 17 that gives you an integer result:
n = (2 * 10^17 - 4) / 19
n = (200000000000000000 - 4) / 19
n = 199999999999999996 / 19
n = 10526315789473684

Just put a 2 at the end and you have your answer:

105263157894736842
x 2
---------------------------------
210526315789473684

Edit: I just read Joseph's method and I like it better.

2 / 2 = 1 remainder 0 (carry down 1 to the next division)
1 / 2 = 0 remainder 1 (carry down 10 to the next division)
10 / 2 = 5 remainder 0 (carry down 5 to the next division)
5 / 2 = 2 remainder 1 (carry down 12 to the next division)
12 / 2 = 6 remainder 0 (carry down 6 to the next division)
6 / 2 = 3 remainder 0 (carry down 3 to the next division)
3 / 2 = 1 remainder 1 (carry down 11 to the next division)
11 / 2 = 5 remainder 1 (carry down 15 to the next division)
15 / 2 = 7 remainder 1 (carry down 17 to the next division)
17 / 2 = 8 remainder 1 (carry down 18 to the next division)
18 / 2 = 9 remainder 0 (carry down 9 to the next division)
9 / 2 = 4 remainder 1 (carry down 14 to the next division)
14 / 2 = 7 remainder 0 (carry down 7 to the next division)
7 / 2 = 3 remainder 1 (carry down 13 to the next division)
13 / 2 = 6 remainder 1 (carry down 16 to the next division)
16 / 2 = 8 remainder 0 (carry down 8 to the next division)
8 / 2 = 4 remainder 0 (carry down 4 to the next division)
4 / 2 = 2 remainder 0

You can stop here because you have gotten to a 2. Now read the digits going down:
105263157894736842

Note: technically you could repeat the process and get a larger number, but it would just be this sequence of digits repeated, e.g.:
105263157894736842 105263157894736842

One final note:
You could even do this the other direction and it might be easier:
The lowest digit is 2. If you double this, you get 4.
..42
Then double the 4:
..842
Then double the 8 (remember the carry):
..(1)6842
Then double the 6 and add the carry (13), that gets you another carry:
..(1)36842
Double the 3 and add the carry (7)
..736842
Double the 7 (remember the carry)
..(1)4736842
Double the 4 and add the carry (9)
..94736842
Double the 9 and remember the carry
..(1)894736842
Double the 8 and add the carry (17), remember the new carry:
..(1)7894736842
etc.
..(1)57894736842
..(1)157894736842
..3157894736842
..63157894736842
..(1)263157894736842
..5263157894736842
..(1)05263157894736842
Now when you double you get back to the digit 2 so you are done:

Answer:
105263157894736842
于 2012-12-31T21:00:11.753 に答える
3

私よりずっと頭のいい人が、この問題の数式を考え出しました。

寄生数の式

...これは、力ずくではないアプローチをコーディングする良い方法です。

(n = 桁数、a = オフセット)

txtResult.Text = string.Empty;
for (int n = 2; n <= 100; n++)
{
    if (((ulong)(Math.Pow(10, n)) - 2) % 19 == 0)
    {
        for (ulong a = 1; a <= 9; a++)
        {
            var omgwut = (ulong)((decimal)Math.Pow(10, n+1) / 19m) * a;

            txtResult.Text = string.Format("{0}, {1}", omgwut.ToString(), txtResult.Text);
        }
    }
}

最終的に次の結果が得られます。

473684210526315789, 
421052631578947368, 
368421052631578947, 
315789473684210526, 
263157894736842105, 
210526315789473684, 
157894736842105263, 
105263157894736842, 
52631578947368421

この質問をした人はサディストだと判断しました。:)

于 2012-12-31T22:13:34.463 に答える
0

あなたは実際に鉛筆と一枚の紙でこれを行うことができます. 18 桁の数字は 2 で終わることがわかっているので、2 倍の大きさの数字は 4 で終わる必要があります。したがって、2 の次の数字は 4 で、次の数字は 8 です。ダースを乗算して保持する方法 (8X2 = 16、6X2+1= 13、3X2+1=7) を知る必要があり、2 が上に 1 のマークがない状態になるまで続けます。これは、210526315789473684 と 105263157894736842 を同時に見つけた方法です。

于 2013-08-13T08:34:25.257 に答える