最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

1300*C. Product of Three Numbers(质数数学)

维修 admin 33浏览 0评论

1300*C. Product of Three Numbers(质数数学)

Problem - 1294C - Codeforces

解析:

        首先这个数肯定不是质数,然后找到第一个因子p,对于n/p再判断质数,然后找到另外两个因子即可。

        注意三个因子不能相同。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int t,n,a[N]; 
bool check(int x){if(x<2) return false;for(int i=2;i<=x/i;i++) if(x%i==0) return false;return true;
}
signed main(){scanf("%lld",&t);while(t--){scanf("%lld",&n);if(check(n)) puts("NO");else{int p=0,q=0;for(int i=2;i<=n/i;i++){if(n%i==0){p=i;n/=i;break;}}if(check(n)) puts("NO");else{for(int i=2;i<=n/i;i++){if(n%i==0&&i!=p){q=i;n/=i;break;}}if(p&&q&&p!=n&&q!=n) printf("YES\n%lld %lld %lld\n",p,q,n);else puts("NO");}}}return 0;
}

1300*C. Product of Three Numbers(质数数学)

Problem - 1294C - Codeforces

解析:

        首先这个数肯定不是质数,然后找到第一个因子p,对于n/p再判断质数,然后找到另外两个因子即可。

        注意三个因子不能相同。

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int t,n,a[N]; 
bool check(int x){if(x<2) return false;for(int i=2;i<=x/i;i++) if(x%i==0) return false;return true;
}
signed main(){scanf("%lld",&t);while(t--){scanf("%lld",&n);if(check(n)) puts("NO");else{int p=0,q=0;for(int i=2;i<=n/i;i++){if(n%i==0){p=i;n/=i;break;}}if(check(n)) puts("NO");else{for(int i=2;i<=n/i;i++){if(n%i==0&&i!=p){q=i;n/=i;break;}}if(p&&q&&p!=n&&q!=n) printf("YES\n%lld %lld %lld\n",p,q,n);else puts("NO");}}}return 0;
}
发布评论

评论列表 (0)

  1. 暂无评论