“高教社杯”第三届福建省大学生程序设计竞赛

本文探讨了在不同进制下求解等式的最大k值,并涉及地板函数的求和应用,适合计算机科学和编程爱好者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Link: 点击打开链接


Problem 2102 Solve equation

Accept: 598    Submit: 1324
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

You are given two positive integers A and B in Base C. For the equation:

A=k*B+d

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

For each test case, output the solution “(k,d)” to the equation in Base 10.

 Sample Input

32bc 33f 16123 100 101 1 2

 Sample Output

(0,700)(1,23)(1,0)

 Source

“高教社杯”第三届福建省大学生程序设计竞赛


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()+")");
			}
	}
}


Problem 2104 Floor problem

Accept: 594    Submit: 668
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

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.

 Input

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).

 Output

For each test case, print the result of f(n,L)+f(n,L+1)+...+f(n,R) in a single line.

 Sample Input

31 2 3100 2 100100 3 100

 Sample Output

0382332

 Source

“高教社杯”第三届福建省大学生程序设计竞赛

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());
			}
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林下的码路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值