zoukankan      html  css  js  c++  java
  • Codeforces1454D D. Number into Sequence

    D. Number into Sequence
    time limit per test
    3 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given an integer nn (n>1n>1).

    Your task is to find a sequence of integers a1,a2,,aka1,a2,…,ak such that:

    • each aiai is strictly greater than 11;
    • a1a2ak=na1⋅a2⋅…⋅ak=n (i. e. the product of this sequence is nn);
    • ai+1ai+1 is divisible by aiai for each ii from 11 to k1k−1;
    • kk is the maximum possible (i. e. the length of this sequence is the maximum possible).

    If there are several such sequences, any of them is acceptable. It can be proven that at least one valid sequence always exists for any integer n>1n>1.

    You have to answer tt independent test cases.

    Input

    The first line of the input contains one integer tt (1t50001≤t≤5000) — the number of test cases. Then tt test cases follow.

    The only line of the test case contains one integer nn (2n10102≤n≤1010).

    It is guaranteed that the sum of nn does not exceed 10101010 (n1010∑n≤1010).

    Output

    For each test case, print the answer: in the first line, print one positive integer kk — the maximum possible length of aa. In the second line, print kk integers a1,a2,,aka1,a2,…,ak — the sequence of length kk satisfying the conditions from the problem statement.

    If there are several answers, you can print any. It can be proven that at least one valid sequence always exists for any integer n>1n>1.

    Example
    input
    Copy
    4
    2
    360
    4999999937
    4998207083
    
    output
    Copy
    1
    2 
    3
    2 2 90 
    1
    4999999937 
    1
    4998207083 

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <vector>
     5 using namespace std;
     6 
     7 typedef long long ll;
     8 
     9 const int N = 2e5+10;
    10 int T;
    11 ll n;
    12 
    13 bool prime[N+1];
    14 vector<int> primes;
    15 void isprime(){
    16     memset(prime, 1, sizeof(prime));
    17     //for(int i = 0; i <= N; i++) prime[i] = 1;
    18     prime[0] = prime[1] = 0;
    19     for (int i = 2; i <= N; i++) {
    20         if(prime[i]){
    21             for(int j = i+i; j <= N; j+=i){
    22                 prime[j] = 0;
    23             }
    24         }
    25     }
    26     for(int i = 1; i <= N; i++)
    27         if(prime[i])
    28             primes.push_back(i);
    29     
    30 }
    31 
    32 int sum = 0, id;
    33 void count(int x){
    34     ll w = n;
    35     int cnt = 0;
    36     while(w % x == 0){
    37         ++cnt;
    38         w /= x;
    39     }
    40     if(cnt > sum){
    41         sum = cnt;
    42         id = x;
    43     }
    44 }
    45 
    46 int main(){
    47     isprime();
    48     scanf("%d", &T);
    49     while(T--){
    50         sum = 0; id = 0;
    51         scanf("%lld", &n);
    52         bool fff = 0;
    53         for(int i = 0; i < primes.size(); i++){
    54             if(n % primes[i] == 0){
    55                 fff = 1;
    56                 count(primes[i]);
    57             }
    58         }
    59         if(!fff){
    60             printf("%d
    %lld
    ", 1, n);
    61             continue;
    62         }
    63         printf("%d
    ", sum);
    64         for(int i = 1; i < sum; i++){
    65             printf("%d ", id);
    66             n /= id;
    67         }
    68         printf("%lld
    ", n);
    69         
    70         
    71     }
    72 
    73     return 0;
    74 }
  • 相关阅读:
    Mysql 关于 FOUND_ROWS() 和 ROW_COUNT() 函数
    MySQL数据库远程连接
    MySQL数据库远程连接
    Linux 下不得不说的那些快捷键
    Linux 下不得不说的那些快捷键
    linux实时查看更新日志命令
    linux实时查看更新日志命令
    the current differences between MyISAM and InnoDB storage engines
    Difference Between InnoDb and MyISAM(个人觉着是好文章,简单易懂,推荐看)
    MyISAM to InnoDB: Why and How(MYSQL官方译文)
  • 原文地址:https://www.cnblogs.com/sineagle/p/14529438.html
Copyright © 2011-2022 走看看