80pts求优化
查看原帖
80pts求优化
757432
laijingnian楼主2023/11/11 18:30
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in freopen("in.txt","r",stdin);
#define out freopen("out.txt","w",stdout);
#define endl "\n"

typedef long long ll;
const ll MOD = 998244353;//1e9+7
const ll N = 2e5+10;
const ll MAXBIT = 60;
const ll INF = 1e18;
const double eps = 1e-8;

ll a;

ll dec_to_bin(ll n)
{
	string s;
    while(n)  
    {    
        s += (n % 2) + '0';  
        n /= 2;  
    }
	reverse(s.begin(),s.end());
	return strtoll(s.c_str(), NULL, 10);
}

int main()
{
	cin >> a;
	// 因为二进制由0和1组成,所以可以用十进制转二进制的方法依次尝试所有的积 
	for(ll i = 1;i;i++)
	{
		auto ans = dec_to_bin(i);
		if(ans % a == 0)
		{
			cout << ans / a << " " << ans;
			return 0;
		}
	}
    return 0;
}


2023/11/11 18:30
加载中...