B - Fox Dividing Cheese CodeForces - 371B

在这里插入图片描述
在这里插入图片描述

题意:把两块饼可以变成原来1/2/ , 1/3 , 1/5,问你多少步可以变成质量相同的两块。
题解:看这个数由多少2、3、5组成,统计2、3、5个数的同时不断用n去除以它们,除完以后得到的a , b如果不相同就不行,如果相同,那么2、3、5个数的差就是步骤

#include<bits/stdc++.h>
#include<cstring>
using namespace std;
int main()
{
	int a,b,flag = 0;
	int arr[] ={2,3,5};
	int ca[3] = {0},cb[3] = {0};
	
	scanf("%d%d",&a,&b);
	
	if(a == b) flag =1;
	for(int i = 0 ; i < 3 ; i++)
	{
		while(a%arr[i] == 0)
		{
			ca[i]++;
			a/=arr[i];
		}
		while(b%arr[i] == 0)
		{
			cb[i]++;
			b/=arr[i];
		}		
	}
	if(a!=b) printf("-1");
	else
	{
		int num = 0;
		for(int i = 0 ; i < 3 ; i++)
		num+=abs(ca[i] - cb[i]);
		printf("%d\n",num);
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`integrate-series-tail` is a function used in the definition of stream-based power series expansions. It takes a stream representing the coefficients of a power series, and returns a new stream representing the coefficients of the antiderivative of that series. Here's the definition of `integrate-series-tail`: ``` (define (integrate-series-tail s) (stream-cons 0 (add-series-tail (scale-series-tail s 1/2) (integrate-series-tail (stream-cdr s))))) ``` The function first creates a new stream with a leading coefficient of 0, since the antiderivative of a power series has no constant term. It then uses two other functions, `add-series-tail` and `scale-series-tail`, to combine and manipulate the coefficients of the input stream. `add-series-tail` takes two streams representing power series, and returns a new stream representing the sum of those series. `scale-series-tail` takes a stream representing a power series, and a scalar value, and returns a new stream representing the series with each coefficient multiplied by that scalar. In the definition of `integrate-series-tail`, we use `scale-series-tail` to multiply the input stream by `1/2`, since the antiderivative of a power series is obtained by dividing each coefficient of the original series by the corresponding power of the variable. We then use `add-series-tail` to combine this scaled stream with the recursively computed antiderivative of the tail of the input stream. This recursive computation of the antiderivative of the tail of the input stream is what allows us to generate the coefficients of the power series for the antiderivative. By repeatedly integrating the series, we can generate the coefficients of the power series for any number of antiderivatives of the original function.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值