FZOJ2102:Solve equation
来源:互联网 发布:dsp广告系统架构php 编辑:程序博客网 时间:2024/05/16 17:43
You are given two positive integers A and B in Base C. For the equation:
We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.
For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:
(1) A=0*B+123
(2) A=1*B+23
As we want to maximize k, we finally get one solution: (1, 23)
The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.
Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.
Output
Sample Input
Sample Output
#include <stdio.h>#include <string.h>int t,c,i,j,x,y,k,d;char a[1005],b[1005];int pow(int c,int k){int i,ans = 1;for(i = 1;i<=k;i++)ans*=c;return ans;}int change(char *a)//进制转换{int i,len,ans = 0;len = strlen(a);for(i = 0;i<len;i++){if(a[i]>='0' && a[i]<='9')ans +=pow(c,len-1-i)*(a[i]-'0');elseans +=pow(c,len-1-i)*(a[i]-'a'+10);}return ans;}int main(){scanf("%d",&t);while(t--){scanf("%s%s%d",a,b,&c);x = change(a);//转换为十进制y = change(b);k = x/y;//求kd = x-k*y;printf("(%d,%d)\n",k,d);}return 0;}
- FZOJ2102:Solve equation
- Solve equation
- Solve equation
- Solve equation
- Solve equation
- Solve equation
- FZU 2102 Solve equation
- FZU 2102 Solve equation
- FZU - 2102 Solve equation
- FZU-2102-Solve equation
- FZU 2102Solve equation
- 640. Solve the Equation
- 640. Solve the Equation
- Solve the Equation
- Can you solve this equation?
- FZU Problem 2102 Solve equation
- Can you solve this equation?
- Can you solve this equation?
- awk 正则表达式、正则运算符详细介绍
- jquery ajax load
- FCLK/HCLK/PCLK的配置
- android实现主动推送小结
- shell中awk详解 (模式提取)
- FZOJ2102:Solve equation
- 简单的题目3
- cursor_sharing 参数
- 解析DirectShow SDK提供的播放器例子源码PlayWnd
- HDU 4651 Partition
- linux 下 reboot和init 6的区别
- Express之初体验
- 小米的商业模式
- poj(1459)Power Network