1 条题解

  • 0
    @ 2025-4-12 22:06:17

    C :

    #include<stdio.h>
    int sum;
    int judge(int a,int b)
    {
    	if((a%b+a/b)/b)
    	{
    	sum+=(a%b+a/b)/b;
    	a=a%b+a/b;
    	return judge(a,b);
    	}
    	else
    	return sum;
    	
    }
    main()
    {
    	int n,m,d;
    	scanf("%d",&n);
    	while(n--)
    	{
    		sum=0;
    		scanf("%d %d",&m,&d);
    			sum=m+m/d;
    			judge(m,d);
    			printf("%d\n",sum);
    	}
    }
    

    C++ :

    #include <stdio.h>
    int main()
    {
    	int n , v, k ,re , sum ,fre ,temp ,temp2;
    	scanf("%d",&n);
    	while(n--)
    	{
    		scanf("%d%d",&v,&k);
    		sum = v + v / k;
    		fre = v % k ;
    		re = v / k ;
    		temp = fre +re;
    		while(temp >=k)
    		{
    			sum = sum + (fre + re) / k;
    			temp2 = fre+re;
    			temp = (fre + re) % k +(fre + re) /k;
    			fre = temp2 %k;
    			re = temp2 /k;
    		}
    		printf("%d\n",sum);
    	}
    }
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    	public static void main(String[] args) {
    		Scanner input=new Scanner(System.in);
    		int s=input.nextInt();
    		int n=0,m=0;
    		
    		for(int i=1;i<=s;i++) {
    			n=input.nextInt();
    			m=input.nextInt();
    			int sum=n;
    			while(n/m>0) {
    				sum+=n/m;
    				n=n/m+n%m;
    			}
    			System.out.println(sum);
    		}
    	}
    }
    
    • 1

    信息

    ID
    2816
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者