首页 > 其他分享 >abc284D Happy New Year 2023

abc284D Happy New Year 2023

时间:2024-10-18 22:21:05浏览次数:1  
标签:std prime abc284D int long i64 Year New

给定整数N,已知N可以写成ppq的形式,其中p和q为不同质数,求p和q。
1<=N<=9E18

分析:p与q的最小值不超过3E6,可以枚举。

#include <bits/stdc++.h>
using i64 = long long;

std::vector<int> minp, prime;
void sieve(int n) {
	minp.assign(n + 1, 0);
	prime.clear();
	for (int i = 2; i <= n; i++) {
		if (minp[i] == 0) {
			minp[i] = i;
			prime.push_back(i);
			for (int j = 2 * i; j <= n; j += i) {
				if (minp[j] == 0) {
					minp[j] = i;
				}
			}
		}
	}
}

void solve() {
	i64 N;
	std::cin >> N;
	for (auto x : prime) {
		if (N % x == 0) {
			N /= x;
			if (N % x == 0) {
				i64 y = N / x;
				std::cout << x << " " << y << "\n";
			} else {
				i64 y = std::sqrt(N);
				std::cout << y << " " << x << "\n";
			}
			return;
		}
	}
}

int main() {
	std::cin.tie(0)->sync_with_stdio(0);
	sieve(3E6);
	int t = 1;
	std::cin >> t;
	while (t--) solve();
	return 0;
}

标签:std,prime,abc284D,int,long,i64,Year,New
From: https://www.cnblogs.com/chenfy27/p/18475160

相关文章

  • C. New Game (二分)
    时隔多年又做题了这不得来水一篇博客题意:给出n个数,取一段连续的数字,最大数和最小数的差不超过k,使得取的数最多。解:对于每一个数,找到第最后一个连续的且与其差值不大于k的数,数一数期间一共有几个,然后取最大值。实现上先处理出连续的段,对于每一个数,找到对应的段,二分找出差值不大于......
  • 《A Heart like Fragrance, Endless Yearning》
    Sinceancienttimes,whohasaheartlikefragrantashers?Thatheartislikeabloomingflowerinspring,fulloffragrance,tendernessandvivacity.Inthelongriveroftime,itblossomsalonewithuniquebrilliance.Nobodyknowswhocantrulyunderst......
  • bolt.new本地化运行踩坑
    接入OpenAI端点安装依赖pnpmadd@ai-sdk/openaidiff--gita/app/lib/.server/llm/model.tsb/app/lib/.server/llm/model.tsindexf0d695c..5217697100644---a/app/lib/.server/llm/model.ts+++b/app/lib/.server/llm/model.ts@@-1,9+1,34@@import{createAnthro......
  • Loading class `com.mysql.jdbc.Driver’. This is deprecated. The new driver class
    原文链接:Loadingclass`com.mysql.jdbc.Driver’.Thisisdeprecated.Thenewdriverclassis`com.mysql.cj.jdbc.Driver’.–每天进步一点点(longkui.site)某日构建springboot项目时,报的错:Loadingclass`com.mysql.jdbc.Driver'.Thisisdeprecated.Thenewdriver......
  • NewStar2024-week2-Crypto
    Crypto茶里茶气fromCrypto.Util.numberimport*flag="flag{*****}"assertlen(flag)==25a=""foriinflag:a+=hex(ord(i))[2:]l=int(a,16).bit_length()print("l=",l)v0=int(a,16)>>(l//2)v1=int(......
  • 学有感《The 12 Week Year》
    猜想公理:二次创造是人类伟大的工具。第一次在脑中,第二次在真实世界中。从[[......
  • Educational Codeforces Round 170 (Rated for Div. 2) C. New Games
    题意转化找一些相邻的数(其中相邻定义为递增序下任意相邻两数差\(\leq1\))求相邻数中,不同数字有\(k\)种,取到数字个数的最大值算法容易想到按顺序排列观察到有点像滑动窗口,考虑用队列维护一个出现不同数字次数为\(k\)的区间,再计算代码来自转载地址voidsolv......
  • JNI(Java Native Interface)和NIO(New Input/Output)是什么?
    1.JNI(JavaNativeInterface)JNI是一种接口,允许Java代码与其他编程语言(例如C或C++)编写的本地代码进行交互。通过JNI,Java程序可以调用本地代码中的函数或库,反过来,本地代码也可以访问Java的对象和方法。JNI通常在以下场景中使用:系统级别操作:有时Java无法直接访问操作系统的......
  • Boost Data Visualization with a New Gauge Control
    BoostDataVisualizationwithaNewGaugeControlCodejockToolkitPro24.0.0helpsusersexperiencemodern,customizablegaugesthatbringdatatolife,inasingle,versatilecomponent.CodejockToolkitProisacomprehensivesuiteofUIcomp......
  • CF908D-New Year and Arbitrary Arrangement
    CF908D-NewYearandArbitraryArrangement前言不是这题为啥星\(2200\)啊,感觉做的很多\(3000\)左右的题都比这道题水吧。简化题意给定空字符串,每次在串尾加入\(a\)或\(b\),各有一定概率。若其中有\(\gek\)个\(ab\)子序列,则停止加入。问至加入结束时,含有\(a......