zoukankan      html  css  js  c++  java
  • 素因子分解

    使用唯一素因子分解定理进行:

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <cstring>
     4 #define ll long long
     5 const int MAX_N = 1000;
     6 int f[MAX_N + 1]; // 存储素因子
     7 int e[MAX_N + 1]; // 素因子的幂次
     8 int prime_factors(int n){
     9     memset(f,0,sizeof f),memset(e,0,sizeof e);
    10     int cnt = 0; // 素因子的个数
    11     int m = (int)sqrt(n + 0.5);
    12     for(int i = 2 ; i <= m ; i++)if(n % i == 0){
    13         f[cnt] = i;
    14         while(n % i == 0) n /= i,e[cnt]++;
    15         cnt++;
    16     }
    17     if(n > 1) f[cnt] = n,e[cnt++] = 1;
    18     return cnt;
    19 }
    20 int main(){
    21     for(int i = 2 ; i <= 100 ; i++){
    22         int cnt = prime_factors(i); printf("%d:",i);
    23         for(int j = 0 ; j < cnt ; j++){
    24             printf("%d^%d",f[j],e[j]);
    25             if(j != cnt - 1) printf("*");
    26         }
    27         printf("
    ");
    28     }
    29     return 0;
    30 }
  • 相关阅读:
    P4297 [NOI2006]网络收费
    P4207 [NOI2005]月下柠檬树
    bzoj2517 矩形覆盖
    bzoj2506 calc
    ......
    SP1811 LCS
    CF585E Present for Vitalik the Philatelist
    好康的
    CF605E Intergalaxy Trips
    字符串
  • 原文地址:https://www.cnblogs.com/cyb123456/p/5838487.html
Copyright © 2011-2022 走看看