bolt
Try our new interface for solving problems
Problems

# Prime Factors

published at 12/18/19, 11:49:37 am

wqe

published at 9/18/23, 5:51:32 pm

# include <bits/stdc++.h>

using namespace std; int main(){ vector<int> v; int n , x; cin>>x; while(x--){ cin>>n; while(n%2 == 0){ v.push_back(2); n = n/2; } for(int i = 3; i <= sqrt(n); i += 2){ while(n%i == 0){ v.push_back(i); n = n/i; } } if(n > 2){ v.push_back(n); } int g = v.size(); for( int i = 0 ; i < v.size() ; i++){ if(i == g - 1){ cout<<v[i]<<endl; } else{ cout<<v[i]<<" "<<"*"<<" "; } } v.clear(); }}

published at 9/18/23, 7:55:26 pm

# define ll long long

using namespace std; int main () { int t; cin >> t; for(ll i = 1; i <= t; i++){ ll n; cin >> n; vector<int> v; while(n%2==0){ v.push_back(2); n/=2; } for(ll j = 3; j * j <= n; j+=2){ if(n%j == 0){ v.push_back(j); n/=j; j-=2; } } if(n > 2){ v.push_back(n); } for(ll z = 0; z < v.size(); z++){ if(z != v.size() - 1){ cout << v[z] << " * "; } else { cout << v[z]; } } cout << endl; } }