21,497
社区成员
发帖
与我相关
我的任务
分享
def say3(n)
mans = (1..n).to_a;turns=count3 = 0
while mans.size>1
mans.reject! {|man| count3+=1;count3%3 == 0};p "#{turns+=1} turn : #{mans}"
end;p "luck man'index is #{mans[0]}"
end
def say3(n)
mans = (1..n).to_a
turns=count3 = 0
while mans.size>1
mans.reject! {|man| count3+=1;count3%3 == 0}
p "#{turns+=1} turn : #{mans}"
end
p "luck man'index is #{mans[0]}"
end
say3 27
"1 turn : [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26]"
"2 turn : [1, 2, 5, 7, 10, 11, 14, 16, 19, 20, 23, 25]"
"3 turn : [1, 2, 7, 10, 14, 16, 20, 23]"
"4 turn : [1, 2, 10, 14, 20, 23]"
"5 turn : [2, 10, 20, 23]"
"6 turn : [10, 20]"
"7 turn : [10, 20]"
"8 turn : [20]"
"luck man'index is 20"
#include <stdio.h>
int main(void)
{
int n, i, s=0;
printf ("N = ");
scanf("%d", &n);
for (i=2; i<=n; i++)
s=(s+3)%i;
printf (" %d\n", s+1);
return 0 ;
}
.386
.model flat, stdcall
option casemap :none
includelib msvcrt.lib
scanf PROTO C :DWORD, :VARARG
printf PROTO C :DWORD, :VARARG
getchar PROTO C
.data
szResult byte "result is %d", 0
szFormat byte "%d", 0
n DWORD 0
.CODE
START:
invoke scanf, offset szFormat, offset n
xor edi, edi
mov ecx, 2
step:
add edi, 3
xor edx, edx
mov eax, edi
div ecx
mov edi, edx
inc ecx
cmp ecx, n
jbe step
inc edi
invoke printf, offset szResult, edi
invoke getchar
ret
end START