• Codeforces 1294C Product of Three Numbers


    题目链接:

    Codeforces 1294C Product of Three Numbers

    思路:

    此题就是求一个数的约数:一个数n的约数可以从2遍历到sqrt(n),最后它本身也是一个约数;
    此题就是求出两个这样的约数,第三个数就是原数除以前两个约数的结果;注意三个数都需要大于1且互不相同;

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    inline int find(int x, int st) {
    	if(x < 2) return -1;
    	int sq = sqrt(x) + 1;
    	for(int i = st; i <= sq; i++) {
    		if(x % i == 0) return i;	
    	}
    	return x >= st ? x : -1;
    }
    
    int main() {
    #ifdef MyTest
    	freopen("Sakura.txt", "r", stdin);
    #endif	
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	int t;
    	cin >> t;
    	while(t--) {
    		int n;
    		cin >> n;
    		int a, b, c;
    		a = find(n, 2);
    		if(a == -1) { cout << "NO
    "; continue; }
    		n /= a;
    		b = find(n, a + 1);
    		if(b == -1) { cout << "NO
    "; continue; }
    		n /= b;
    		if(n == a || n == b || n <= 2) { cout << "NO
    "; continue; }
    		cout << "YES
    " << a << ' ' << b << ' ' << n << '
    ';
    	}
    	return 0;
    }
    
  • 相关阅读:
    解决maven无法下载jar的问题
    Vue-Router 基础
    VUE自定义组件
    VUE过滤器
    VUE生命周期函数
    VUE表单输入绑定
    VUE计算属性和监听器
    VUE 模板语法
    VUE介绍
    taro3.x: 函数组件createIntersectionObserver
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308648.html
Copyright © 2020-2023  润新知