天涯小站 2.0

 找回密码
 注册
搜索
天涯小站 2.0 首页 拾萃 时尚生活 查看内容

蜂王:几个鸡蛋?

2017-1-20 02:23 PM| 发布者: 星光| 查看: 731| 评论: 25|原作者: waspking

摘要: 不会手算, 就写了这个:for (i in 1:100000) { if (i %% 1 != 0) {next} else if (i %% 2 != 1) {next} else if (i %% 3 != 0) {next} else if (i %% 4 != 1) {next} else if (i %% 5 != 4) {next} else if (i %% ...


不会手算, 就写了这个:



for (i in 1:100000)
{
             if (i %% 1 != 0) {next}
        else if (i %% 2 != 1) {next}
        else if (i %% 3 != 0) {next}
        else if (i %% 4 != 1) {next}
        else if (i %% 5 != 4) {next}
        else if (i %% 6 != 3) {next}
        else if (i %% 7 != 0) {next}
        else if (i %% 8 != 1) {next}
        else if (i %% 9 != 0) {next}
        print (i)
}

很快出来很多结果!



发表评论

最新评论

引用 2017-3-2 01:43 PM
waspking: 是挑战一下自己的编程能力。 要不R会慢慢忘记的。
I see, I have forgotten all of them.
引用 2017-3-1 08:24 PM
fancao: 用计算机不算本事。要用心算,其实很简单。
首先,应该找7和9 的公倍数,(不是公约数),其次,考虑其他的质数,尾数是9就能符合5 和6的要求。再找符合8的条件 ...
是挑战一下自己的编程能力。 要不R会慢慢忘记的。
引用 2017-3-1 07:26 PM
waspking: 189 is not right. 189 mod 8 = 5.
用计算机不算本事。要用心算,其实很简单。
首先,应该找7和9 的公倍数,(不是公约数),其次,考虑其他的质数,尾数是9就能符合5 和6的要求。再找符合8的条件。这时,2,3,4都已经自然通过了,不必再考虑。综合起来,尝试用63* 13, 63*23……依次往下推算,取最小的值即可,毕竟只有一筐鸡蛋啊,两步就可得到结果,1449。      
引用 2017-1-20 08:35 PM
xcr: 哈哈,不是江山,是谷山。
哈哈哈。。。
引用 2017-1-20 03:16 PM
谷山歌: 是,太粗心太自信。。。从小就是这毛病,江山易改,本性难易
哈哈,不是江山,是谷山。
引用 2017-1-20 03:10 PM
swan.eagle: 阿哥性急而草率了       
我以前不会,是现在刚从阿哥的算法学习触动的认识,谢谢师傅      
是,太粗心太自信。。。从小就是这毛病,江山易改,本性难移
引用 2017-1-20 03:03 PM
八月风: 189别的好像都符合,但拿8个的余数不对啊?
同意你说的1和2,但符合所有条件最小的数不是189,是1449?
Oops。。。没仔细查证。
引用 2017-1-20 01:30 PM
63*23, 63*63, 63*103, 63*143...63*(23+40*i), where i =1, 2, 3....also satisfy the statements.
引用 2017-1-20 01:21 PM
swan.eagle: 应该是这个数吧189*65*9*9=995085,蜂王的筐是装花粉做的鸡蛋呢
your number is rather large! there are many answers before yours.
e.g. 1449, 3969, 6489....in general, any number that fits 1449+2520*i, where i=1 to infinity, will be good for the number of eggs to satisfy the original statements.
引用 2017-1-20 01:17 PM
轻风: 星期5,吐血奉献:

#!/bin/bash
k=2
j=$1
while :
do
        if [ $k -lt $j ]
        then

                i=`expr 63 \* $k`
                echo 63 X  ...
way too complicated for me. the beauty of mine is that it corresponds exactly as the Chinese statement. so it is very easy to modify, next time there is a different question. for example if you change all to 0 (for 1 to 9, everything works whether you take 1, 2, 3...9, you always have 0 left). then i just change these numbers to 0 and get the answer 2520.
引用 2017-1-20 01:04 PM
星期5,吐血奉献:

#!/bin/bash
k=2
j=$1
while :
do
        if [ $k -lt $j ]
        then
                i=`expr 63 \* $k`
                echo 63 X $k = $i
                q=`echo $i |awk '{print substr($0,length,1)}'`
                if (([ $q == 9 ] && ([ $(( $i % 6 )) -eq 3 ]) && ([ $(( $i % 8 )) -eq 1 ]))
                then
                                echo “We got a winner! ”
                                echo ”    $i    “                 
                fi
                k=`expr $k + 1`
        fi
done

$ ./count.out 100
We got a winner!
    1449
63 X 23 = 1449
We got a winner!
    3969
63 X 63 = 3969
引用 2017-1-20 09:17 AM
谷山歌: 不用笔算,用心算

189
1. 必须满足是7和9的公约数,最小的公约数是63;
2. 尾数必须是9,才能满足拿 4,5,6,8 所剩余数;
63 X 3 = 189 ...
阿哥性急而草率了    
我以前不会,是现在刚从阿哥的算法学习触动的认识,谢谢师傅   
引用 2017-1-20 09:14 AM
应该是这个数吧189*65*9*9=995085,蜂王的筐是装花粉做的鸡蛋呢
引用 2017-1-20 05:22 AM
韩信点兵法,又叫中国剩余定理。
引用 2017-1-20 03:35 AM
好大的筐
引用 2017-1-20 01:21 AM
孙子定理 。
引用 2017-1-19 11:35 PM
waspking: 189 is not right. 189 mod 8 = 5.
1449  (根据我上面的算法。)  
引用 2017-1-19 11:28 PM
i do not think xcr's code will work. for one thing, it says if it meets all the conditions, then +2. it will never print out i. the +2 should be after "else" and print i should be inside the loop.
引用 2017-1-19 11:23 PM
xcr: 不好意思,文学青年只有这点能耐。    
(i %% 9 != 0) )

you have an extra ) here.
i do not think you tested your code.

i tested mine before publishing them  
引用 2017-1-19 11:17 PM
谷山歌: 不用笔算,用心算

189
1. 必须满足是7和9的公约数,最小的公约数是63;
2. 尾数必须是9,才能满足拿 4,5,6,8 所剩余数;63 X 3 = 189 ...
189 is not right. 189 mod 8 = 5.

查看全部评论(25)

手机版|天涯小站

GMT-5, 2026-4-29 01:11 PM

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

返回顶部