FOJ 1075

#include<stdio.h>
#include<iostream>
using namespace std;
int a[8000]={2,3};
int hash[80000]={0};
void func()
{
    int i,j,k=2,flag;
    hash[2]=hash[3]=1;
    for(i=5;k<7100;i+=2)
    {
        flag=1;
        for(j=0;a[j]*a[j]<i;j++)
        {
            if(i%a[j]==0)
            {
                flag=0;
                break;
            }
        }
        if(flag)
        {
            a[k++]=i;
            hash[i]=1;
        }
    }
}
int main()
{
    func();
    //printf("%d\n",a[6990]);
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int p=0;
        scanf("%d",&p);
        while(hash[p]==0)
        {
            for(int j=0;j<6990&&p>=a[j];j++)
            {
                while(p%a[j]==0&&hash[p]==0)
                {
                    printf("%d*",a[j]);
                    p=p/a[j];
                }
            }
        }
        printf("%d\n",p);
    }
    return 0;
}
时间: 2024-08-02 02:13:15

FOJ 1075的相关文章

Foj 1075 分解素因子

题目链接:http://acm.fzu.edu.cn/problem.php?pid=1075 思路:分解素因子 #include <iostream> #include <cstring> #include <cstdio> using namespace std; const int maxn=65535+5; typedef long long LL; bool prime[maxn]; int p[maxn/10]; int k; void isprime()

HDU 1075 What Are You Talking About (Trie树)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 map可以过...我上的字典树,小bug有点尴尬,题目没有明确给出数据范围也是无奈. 贡献了几次RE 一次WA.尴尬.discuss里面有个说注意前缀的到是给了点tip.总体来说不错 代码: 1 #define _CRT_SECURE_NO_WARNINGS 2 #include <functional> 3 #include <algorithm> 4 #include <

FOJ 题目 2075 Substring (后缀数组求出现k次的最小字典序子串)

Problem 2075 Substring Accept: 70    Submit: 236 Time Limit: 1000 mSec    Memory Limit : 65536 KB Problem Description Given a string, find a substring of it which the original string contains exactly n such substrings. Input There are several cases.

HDU 1075 What Are You Talking About(字典树)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 题意:根据词典翻译语句. 思路:裸的字典树.每个节点存以该节点为结尾的对应的单词. 代码: #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> #include <string> #incl

HDU 1075 What Are You Talking About(map运用)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 Problem Description Ignatius is so lucky that he met a Martian yesterday. But he didn't know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leav

线段树 FOJ 2174

FOJ  2174 区间跟新,区间询问: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #define lson l,mid,rt<<1 5 #define rson mid+1,r,rt<<1|1 6 7 using namespace std; 8 typedef long long LL; 9 const int N=110001; 10 int sum[N

ural 1075. Thread in a Space

1075. Thread in a Space Time limit: 1.0 secondMemory limit: 64 MB There are three points in a 3-dimensional space: A, B and C. All the coordinates of the points are integer numbers with absolute values not greater than 1000. A solid ball with a cente

FOJ 2105 Digits Count

题意:对一串数字进行抑或某数,和某数,或某数,统计某区间和的操作. 思路:因为化成二进制就4位可以建4颗线段树,每颗代表一位二进制. and 如果该为是1  直接无视,是0则成段赋值为0: or  如果是0 无视,是1则成段赋值为1: xor 成段亦或,1个数和0个数交换: sum 求和: #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include <

hust 1075 Every String Left Behind

题目描述 Elenore has a list of strings that she wants to put in a file. She could just put them all into a file in order, but she wants to minimize the size of the file. So she figures she can combine all the strings into one large string which contains