杭电 “Prime Bases ”解题报告

本文介绍了一道关于数论的题目——PrimeBases,该题要求将任意正整数转换为一种特殊的混合基数表示形式,即利用一系列连续质数作为基数。文章详细解析了题目的解题思路,并提供了完整的C++代码实现。

Prime Bases

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 26   Accepted Submission(s) : 7
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

Problem Description

Given any integer base b >= 2, it is well known that every positive integer n can be uniquely represented in base b. That is, we can write

n = a0 + a1*b + a2*b*b + a3*b*b*b + ...

where the coefficients a0, a1, a2, a3, ... are between 0 and b-1 (inclusive).

What is less well known is that if p0, p1, p2, ... are the first primes (starting from 2, 3, 5, ...), every positive integer n can be represented uniquely in the "mixed" bases as:

n = a0 + a1*p0 + a2*p0*p1 + a3*p0*p1*p2 + ...

where each coefficient ai is between 0 and pi-1 (inclusive). Notice that, for example, a3 is between 0 and p3-1, even though p3 may not be needed explicitly to represent the integer n.

Given a positive integer n, you are asked to write n in the representation above. Do not use more primes than it is needed to represent n, and omit all terms in which the coefficient is 0.

Input

Each line of input consists of a single positive 32-bit signed integer. The end of input is indicated by a line containing the integer 0.

Output

For each integer, print the integer, followed by a space, an equal sign, and a space, followed by the mixed base representation of the integer in the format shown below. The terms should be separated by a space, a plus sign, and a space. The output for each integer should appear on its own line.

Sample Input

123
456
123456
0

Sample Output

123 = 1 + 1*2 + 4*2*3*5
456 = 1*2*3 + 1*2*3*5 + 2*2*3*5*7
123456 = 1*2*3 + 6*2*3*5 + 4*2*3*5*7 + 1*2*3*5*7*11 + 4*2*3*5*7*11*13

Source

2008 Rocky Mountain Regional 


解题思路:
本题是简单的数论题,数据处理量也不大,不用担心超时的问题,用一个数组prime[]将29及以下的素数全存储起来,然后将素数累乘的积及最大系数+1(这里还没减去,在后面处理)放入一个二维数组sum中。
处理输入数据时,定义一个二维数组a,存放是否使用对应sum中该位置的值是否使用,未使用则继续,使用则减去该存放的值,在a【1】中第一个位置存放1,第二个位置存放系数。循环,在控制输出,就可以了。
本来素数到23就可以了,但是为什么要写到29,思考一下。可能不一定用到,但是我没算,细心的朋友算一下。

代码如下:
#include <iostream>
using namespace std;
int main()
{
	int n,i,j;//数据预处理
	int prime[]={2,3,5,7,11,13,17,19,23,29};
	__int64 sum[10][2],tempcount=1,tempnum=1;
	for(i=0,j=0;i<10;i++)
	{
		sum[i][0]=tempcount;
		sum[i][1]=tempnum;
		tempnum=prime[j]-1;
		tempcount*=prime[j++];
	}//数据处理
	while(cin>>n)
	{
		int out=n;
		if(n==0)break;
		int a[10][2]={0};
		i=9;
		while(n!=0)
		{
			if(n>=sum[i][0])
			{
				for(j=prime[i+1]-1;j>0;j--)
				{
					tempcount=j*sum[i][0];
					if(tempcount<=n)
					{
						a[i][0]=1;
						a[i][1]=j;
						n-=tempcount;
						break;
					}
				}
			}
			else
			{
				a[i][0]=0;
				a[i][1]=0;
			}
			i--;
		}//控制输出
		cout<<out<<" = ";
		int outcount=0;
		for(i=0;i<10;i++)
		{
			if(a[i][0]==1)
			{
				if(i==0)
				{
					cout<<"1";
					outcount++;
				}
				else
				{
					if(outcount!=0)
						cout<<" + ";
					cout<<a[i][1]<<"*";
					for(j=0;j<i;j++)
					{
						cout<<prime[j];
						if(j!=i-1)cout<<"*";
					}
					outcount++;
				}
			}
		}
		cout<<endl;
	}
	return 0;
}


跟网型逆变器小干扰稳定性分析与控制策略优化研究(Simulink仿真实现)内容概要:本文围绕跟网型逆变器的小干扰稳定性展开分析,重点研究其在电力系统中的动态响应特性及控制策略优化问题。通过构建基于Simulink的仿真模型,对逆变器在不同工况下的小信号稳定性进行建模与分析,识别系统可能存在的振荡风险,并提出相应的控制优化方法以提升系统稳定性和动态性能。研究内容涵盖数学建模、稳定性判据分析、控制器设计与参数优化,并结合仿真验证所提策略的有效性,为新能源并网系统的稳定运行提供理论支持和技术参考。; 适合人群:具备电力电子、自动控制或电力系统相关背景,熟悉Matlab/Simulink仿真工具,从事新能源并网、微电网或电力系统稳定性研究的研究生、科研人员及工程技术人员。; 使用场景及目标:① 分析跟网型逆变器在弱电网条件下的小干扰稳定性问题;② 设计并优化逆变器外环与内环控制器以提升系统阻尼特性;③ 利用Simulink搭建仿真模型验证理论分析与控制策略的有效性;④ 支持科研论文撰写、课题研究或工程项目中的稳定性评估与改进。; 阅读建议:建议读者结合文中提供的Simulink仿真模型,深入理解状态空间建模、特征值分析及控制器设计过程,重点关注控制参数变化对系统极点分布的影响,并通过动手仿真加深对小干扰稳定性机理的认识。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值