FACTCG2 - Medium Factorization

no tags 

The task in this problem is to write a number in a multiplication of prime numbers separated by “ x ”. You need to put the number 1 in this multiplication.

Input

The input consists of several lines.

Each line consists of one integer N (1 <= N <= 10^7) .

Output

For each line you need to output the factorization separated by “ x ” and including 1.

Sample

Input
1
2
4
8

Output
1
1 x 2
1 x 2 x 2
1 x 2 x 2 x 2

hide comments
rouge_kitty: 2022-09-05 12:23:01

got TLE twice, then changed *ONE* place where I had used long long int to int, got accepted!!

But a few pointers if you are getting a lot of TLEs:
1) Optimise the sieve as much as you can.
2) Minimise the use of long long int. Use it only where it is unavoidable.
3) For c++ folks, you can use cout, but do not use cin. Use scanf till you hit the EOF.
4) Don't unnecessarily complicate your code with too many loops.

Last edit: 2022-09-05 12:28:29
tracyyi: 2022-06-29 12:39:12

How can we get the test file?

tarun_28: 2020-09-21 21:56:32

O(log(n)) for each query;)

ekesh: 2020-06-11 17:32:40

Changing "while(scanf("%d", &n))" to "while(scanf("%d", &n) != EOF)" took me from TLE to AC.

scolar_fuad: 2019-07-13 11:13:06

Don,t use cin/cout if you do not want to destroy your code.....

use printf and scanf

x_a_h_i_d: 2019-07-12 08:08:27

thanks.learned about new approach!

sagar_june97p: 2019-06-18 19:12:43

cin/cout => TLE.
scanf/printf => AC
use while(scanf("%i", &n) != EOF)

aliakberaakash: 2019-03-28 19:05:02

got tle for not using EOF -_- FML!

eagleshadow: 2018-09-09 00:43:29

Amazing !!
At first thought , i thought it's a very easy problem
but got TLE
then came to know about the concept LPD
Thanks to Phyllipe Medeiros :)

Last edit: 2018-09-27 23:50:14
riyuzaki251097: 2018-09-03 19:12:42

Only reason if u are failing tc 4 is cin cout, tried lots of things, scanf printf solved the issue


Added by:Phyllipe Medeiros
Date:2012-02-26
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64