Link: 点击打开链接
You are given two positive integers A and B in Base C. For the equation:
A=k*B+dWe 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.
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.
java进制转换:
import java.text.*; import java.util.*; import java.math.*; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); BigInteger b1,sum1,sum2,x,t,d,ans1,ans2; int cas,tt,w,k; String s1,s2; char c; tt=cin.nextInt(); for(cas=1;cas<=tt;cas++) { s1=cin.next(); s2=cin.next(); b1=cin.nextBigInteger(); sum1=BigInteger.valueOf(0); sum2=BigInteger.valueOf(0); t=BigInteger.ONE; //System.out.println(s1+s2+b1); for(int i=s1.length()-1;i>=0;i--) { c=s1.charAt(i); if(c>='0'&&c<='9') w=c-'0'; else w=c-'a'+10; sum1=sum1.add(BigInteger.valueOf(w).multiply(t)); t=t.multiply(b1); } //System.out.println(sum1.toString()); t=BigInteger.ONE; for(int i = s2.length()-1;i>=0;i--) { c=s2.charAt(i); if(c>='0'&&c<='9') w=c-'0'; else w=c-'a'+10; sum2=sum2.add(BigInteger.valueOf(w).multiply(t)); t=t.multiply(b1); } //System.out.println(sum2.toString()); ans1=BigInteger.ZERO; ans2=sum2; for(k=0;;k++)//注意:for循环里面变量不能用大数表示!!!即k不能定义为大数!!! { d=sum1.subtract(BigInteger.valueOf(k).multiply(sum2)); if(d.compareTo(BigInteger.ZERO)<0) break; ans1=BigInteger.valueOf(k); ans2=d; } System.out.println("("+ans1.toString()+","+ans2.toString()+")"); } } }
In this problem, we have f(n,x)=Floor[n/x]. Here Floor[x] is the biggest integer such that no larger than x. For example, Floor[1.1]=Floor[1.9]=1, Floor[2.0]=2.
You are given 3 positive integers n, L and R. Print the result of f(n,L)+f(n,L+1)+...+f(n,R), please.
The first line of the input contains an integer T (T≤100), indicating the number of test cases.
Then T cases, for any case, only 3 integers n, L and R (1≤n, L, R≤10,000, L≤R).
import java.text.*; import java.util.*; import java.math.*; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); BigInteger b1,x,t,d,ans; int cas,tt,w,k,l,r; String s1,s2; char c; tt=cin.nextInt(); for(cas=1;cas<=tt;cas++) { //s1=cin.next(); //s2=cin.next(); b1=cin.nextBigInteger(); l=cin.nextInt(); r=cin.nextInt(); ans=BigInteger.ZERO; for(int i=l;i<=r;i++) { ans=ans.add(b1.divide(BigInteger.valueOf(i))); } System.out.println(ans.toString()); } } }