zoukankan      html  css  js  c++  java
  • Intelligent Factorial Factorization LightOJ

    就是暴力嘛。。。很水的一个题。。。

    不好意思交都。。。

    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #define MOD 2018
    #define LL long long
    #define ULL unsigned long long
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int maxn = 10010, INF = 0x7fffffff;
    int primes[maxn], base[maxn], mi[maxn];
    int vis[maxn];
    int ans = 0;
    set<int> s;
    void init()
    {
        mem(vis, 0);
        for(int i=2; i<maxn; i++)
        {
            if(vis[i]) continue;
            primes[ans++] = i;
            for(LL j=(LL)i*i; j<maxn; j+=i)
                vis[j] = 1;
        }
    }
    
    int main()
    {
        init();
        int T, kase = 0;
        scanf("%d",&T);
        while(T--)
        {
            s.clear();
            mem(base, 0);
    
            int n;
            scanf("%d",&n);
            for(int i=2; i<=n; i++)
            {
                int temp = i;
                for(int j=0; j<ans && primes[j] * primes[j] <= temp; j++)
                {
                    while(temp % primes[j] == 0)
                    {
                        temp /= primes[j];
                        base[primes[j]]++;
                    }
                    if(base[primes[j]] > 0)
                    {
                        s.insert(primes[j]);
                    }
                }
                if(temp > 1)
                {
                    base[temp]++;
                    s.insert(temp);
                }
            }
            printf("Case %d: %d = ",++kase, n);
            int cnt = 0;
            for(set<int>::iterator it=s.begin(); it!=s.end(); it++)
            {
                if(cnt == 0)
                    printf("%d (%d)",*it, base[*it]);
                else
                    printf(" * %d (%d)",*it, base[*it]);
                cnt++;
            }
            printf("
    ");
    
        }
    
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    Scrum 冲刺博客第五篇
    Scrum 冲刺博客第四篇
    Scrum 冲刺博客第三篇
    ajax send()
    form action中get post传递参数的问题
    struts2 iterator中if标签的使用
    表格内容自动换行
    从js向Action传中文参数出现乱码问题的解决方法
    java开发环境搭建
    Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9342463.html
Copyright © 2011-2022 走看看