LoginSignup
1

More than 5 years have passed since last update.

Codeforces Beta Round #13

Last updated at Posted at 2013-12-31

はい。

A. Numbers

implementation,math

ざっくりと大意

・2進数からA-1進数までの書くdigitの合計の平均??

方針のようなもの

・n進数の式をおこす。

Note(最初のサンプルケースの説明)

・5を2進数から4進数で表す。
・2進数:101 3進数:12 4進数:11それぞれのdigitの合計は2,3,2

a.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys, io
import re, math
start = time.clock()
a=int(raw_input())
s=0
for n in range(2,a):
    c=a
#sには余りを加算しづける。(和が知りたいので順番は保存する必要なし)
#cは商を代入し続ける。
    while c:s+=c%n;c/=n
x,y=s,a-2
while y:x,y=y,x%y
print str(s/x) +'/'+ str((a-2)/x)

10進数で与えられた数値をn進数に変換する方法は
こんな感じです。
http://www.nowshika.com/joso/img01010112.png

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1