Consecutive Digits POJ - 2710

关于数论的一些问题

1.十进制如何转化为八进制十六进制N进制:正数除N反余,小数乘N取整;翻过来时各个位分别乘以N的x(位数)次幂

As a recruiting ploy, Google once posted billboards in Harvard Square and in the Silicon Valley area just stating “{first 10-digit prime found in consecutive digits of e}.com”. In other words, find that 10-digit sequence and then connect to the web site — and find out that Google is trying to hire people who can solve a particular kind of problem.

Not to be outdone, Gaggle (a loosy-goosy fuzzy logic search firm), has devised its own recruiting problem. Consider the base 7 expansion of a rational number. For example, the first few digits of the base 7 expansion of 1/5 10 = 0.12541... 7, 33/4 10 = 11.15151... 7, and 6/49 10 = 0.06000... 7, From this expansion, find the digits in a particular range of positions to the right of the "decimal" point.

Input
The input file begins with a line containing a single integer specifying the number of problem sets in the file. Each problem set is specified by four base 10 numbers on a single line, n d b e, where n and d are the numerator and denominator of the rational number and 0 <= n <= 5,000 and 1 <= d <= 5,000. b and e are the beginning and ending positions for the desired range of digits, with 0 <= b,e <= 250 and 0 <= (e-b) <= 20. Note that 0 is the position immediately to the right of the decimal point.
Output
Each problem set will be numbered (beginning at one) and will generate a single line:
  • Problem set k: n / d, base 7 digits b through e: result

where k is replaced by the problem set number, result is your computed result, and the other values are the corresponding input values.

Sample Input
4
1 5 0 0
6 49 1 3
33 4 2 7
511 977 122 126
Sample Output
Problem set 1: 1 / 5, base 7 digits 0 through 0: 1
Problem set 2: 6 / 49, base 7 digits 1 through 3: 600
Problem set 3: 33 / 4, base 7 digits 2 through 7: 151515
Problem set 4: 511 / 977, base 7 digits 122 through 126: 12425

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>

int main()
{
    int n,num,p,i,a,b,l,r;
    int ans[5050];
    scanf("%d",&n);
    for(num=1;num<=n;num++)
    {
        memset(ans,0,sizeof(ans));
        scanf("%d %d %d %d",&a,&b,&l,&r);
        p=a;
        a=a%b;
        int k=0;
        while(k<=r)
        {
            a=a*7;
            ans[k]=a/b;
            a=a%b;
            k++;
        }
        printf("Problem set %d: %d / %d, base 7 digits %d through %d: ",num,p,b,l,r);
        for(i=l;i<=r;i++)
        {
            printf("%d",ans[i]);
        }
        printf("\n");
    }
    return 0;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值