Description
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
Output
- 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: 151515Problem set 4: 511 / 977, base 7 digits 122 through 126: 12425
#include<iostream> #include<cmath> #include<algorithm> #include<string> #include<cstring> #include<cstdlib> #define MAX 255 #include<stack> #include<cstdio> using namespace std; int main() { int T,n,d,b,e; cin>>T; for(int i=1;i<=T;i++) { cin>>n>>d>>b>>e; printf("Problem set %d: %d / %d, base 7 digits %d through %d: ",i,n,d,b,e); n%=d; for(int j=0;j<=e;j++) { n*=7; if(j>=b) printf("%d",n/d); n%=d; } cout<<endl; } return 0; }