Number sequence math problem

Number sequence math problem

Regardless of the value of k, the sequence trend is the same.
Take k=2

Idea: first convert to binary,

Insert picture description here

#include<iostream>
using namespace std;


int main()
{
    
    
	
	int k,n;
	cin>>k>>n;
	
	int ans=0;
	
	
	int t=1;
	while(n)
	{
    
    
		if(n&1)
		{
    
    
			ans+=t;
		}
		n=n>>1;
		t*=k;
		
		
	}
	
	cout<<ans;	
	
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45448563/article/details/113732137