More actions
imported>jereneal20 No edit summary |
imported>joojis No edit summary |
||
| Line 5: | Line 5: | ||
// 164K 0MS C 112B | // 164K 0MS C 112B | ||
(define (mod a b) | |||
(if (< a b) | |||
a | |||
(mod(- a b) b) | |||
) | |||
) | |||
(define (quot a b) | |||
(/ (- a (mod a b)) b) | |||
) | |||
(define (BitCount n) | |||
(if (< n 1) | |||
0 | |||
(+ (BitCount (quot n 2)) (mod n 2)) | |||
) | |||
) | |||
(define (SearchBitN n m) | |||
(if (= n (BitCount m)) | |||
m | |||
(SearchBitN n (+ m 1)) | |||
) | |||
) | |||
(define (AnEasyProblem n) | |||
(SearchBitN (BitCount n) (+ n 1)) | |||
) | |||
=== ... === | === ... === | ||
* 첫번째 제출에 상콤하게 Accept! 나름 열심히 줄여본다고 코드를 줄여봤지만. 역시 갈 길이 머네요... -[[정진경]] | * 첫번째 제출에 상콤하게 Accept! 나름 열심히 줄여본다고 코드를 줄여봤지만. 역시 갈 길이 머네요... -[[정진경]] | ||
Revision as of 16:49, 13 June 2011
Describe AnEasyProblem/정진경 here
Source Code
main(n,a,b){for(;a=b=scanf("%d",&n),n;printf("%d\n",n+a*b-b/2)){for(;a&~n;a*=2);for(;(b|a*b)&n;n+=b-a*b,b*=2);}}
// 164K 0MS C 112B
(define (mod a b)
(if (< a b)
a
(mod(- a b) b)
)
)
(define (quot a b)
(/ (- a (mod a b)) b)
)
(define (BitCount n)
(if (< n 1)
0
(+ (BitCount (quot n 2)) (mod n 2))
)
)
(define (SearchBitN n m)
(if (= n (BitCount m))
m
(SearchBitN n (+ m 1))
)
)
(define (AnEasyProblem n)
(SearchBitN (BitCount n) (+ n 1))
)