codeforce - 13A A.Numbers

A. Numbers
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.

Now he wonders what is an average value of sum of digits of the number A written in all bases from 2 to A - 1.

Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.

Input

Input contains one integer number A (3 ≤ A ≤ 1000).

Output

Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.

Sample test(s)
input
5
output
7/3
input
3
output
2/1
Note

In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.

 

#include "stdio.h"
#include "string.h"
#include "stdlib.h"


int n;
int ntable[1000] ;
int su(int d,int n)
{int i=0,sum=0;
 int r[1000];memset(r,0,100);
 int tmp;
 int l;
     while(d!=0)
      {tmp=d%n;
       r[i]=ntable[tmp];
       i++;
       d/=n;
                }
     l=i;
     for(i=0;i<l/2;i++)
      {tmp=r[i];
       r[i]=r[l-i-1];
       r[l-i-1]=tmp;
        }
for(i=0;i<l;i++)
sum+=r[i];
return sum;
}

int gcd(int a,int b){
int r;
while(b>0){
r=a%b;
a=b;
b=r;
}
return a;
}

int main(  )
{
  int a,i=0,ans,fm=0;
  for(i=0;i<1000;i++)
  {
      *(ntable+i)=i;
  }
while(~ scanf( "%d",&a ))
  {
      fm=a-1;ans=0;
   for(i=2;i<=fm;i++)
   {
       ans+=su(a,i) ;
    }
printf( "%d/%d\n",ans/gcd(ans,fm-1),(fm-1)/gcd(ans,fm-1) );
  }
  return 0;
}


 

 

posted @   一杯半盏  阅读(222)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示