FZU OJ 1075 :分解素因子
Accept: 2161 Submit: 4126
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Input
Output
Sample Input
Sample Output
先打表。再用一个数组来储存素数,最后找素数里面能够整除k的素数,把这些素数储存到另一个数组中。
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#define ll long long
using namespace std;
const int maxn=1e6+10;
int a[maxn];
int b[maxn];
int c[maxn];
int main()
{
int k,x;
int i,j,K;
memset(a,0,sizeof(a));
//打表
a[0]=a[1]=1;
for(i=2;i<=65540;i++)
{
if(a[i]==0)
{
for(j=2;j*i<=65540;j++)
{
a[i*j]=1;
}
}
}
//将素数储存到数组b中
int p=0;
for(j=0;j<=65540;j++)
{
if(a[j]==0) b[p++]=j;
}
scanf("%d",&k);
while(k--)
{
memset(c,0,sizeof(c));
int sum=0;
scanf("%d",&x);
int ss;
for(ss=0;ss<p;)
{
if(x==0) break;
//寻找整除x的素数
else if(x%b[ss]==0)
{
c[sum++]=b[ss];
x/=b[ss];
continue;
}
else if(x%b[ss]!=0) ss++;
}
K=sum;
for(i=0;i<K;i++)
{
if(i!=0) printf("*");
printf("%d",c[i]);
}
printf("\n");
}
return 0;
}
FZU OJ 1075 :分解素因子的更多相关文章
- fuzhou 1075 分解素因子
Problem 1075 分解素因子 Accept: 1331 Submit: 2523Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...
- FZU 1075 分解素因子【数论/唯一分解定理/分解素因子裸模板】
[唯一分解定理]:https://www.cnblogs.com/mjtcn/p/6743624.html 假设x是一个正整数,它的值不超过65535(即1<x<=65535),请编写一个 ...
- fzu 1075 分解素因子
代码: #include<cstdio> #include<cstring> #include<iostream> using namespace std; int ...
- 给定n,求1/x + 1/y = 1/n (x<=y)的解数~hdu-1299~(分解素因子详解)
链接:https://www.nowcoder.com/acm/contest/90/F来源:牛客网 题目描述 给定n,求1/x + 1/y = 1/n (x<=y)的解数.(x.y.n均为正整 ...
- LightOJ 1340 - Story of Tomisu Ghost 阶乘分解素因子
http://www.lightoj.com/volume_showproblem.php?problem=1340 题意:问n!在b进制下至少有t个后缀零,求最大的b. 思路:很容易想到一个数通过分 ...
- N!分解素因子及若干问题【转载】
这里写的非常好http://www.cnblogs.com/openorz/archive/2011/11/14/2248992.html,感谢博主,我这里就直接用了. 将N!表示成 N! = p1^ ...
- light oj 1236 分解质因数
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/H 题意:求满足1<=i<=j<=n ...
- LightOj 1236 - Pairs Forming LCM (分解素因子,LCM )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意:给你一个数n,求有多少对(i, j)满足 LCM(i, j) = n, ...
- POJ 1811 Prime Test 素性测试 分解素因子
题意: 给你一个数n(n <= 2^54),判断n是不是素数,如果是输出Prime,否则输出n最小的素因子 解题思路: 自然数素性测试可以看看Matrix67的 素数与素性测试 素因子分解利用 ...
随机推荐
- cookie session localstorage sessionStorage区别
cookie:http://www.cnblogs.com/Darren_code/archive/2011/11/24/Cookie.html 重要特点: 1.cookie 有大小设置,有过期时间设 ...
- WPF编程学习 —— 样式
本文目录 1.引言 2.怎样使用样式? 3.内联样式 4.已命名样式 5.元素类型样式 6.编程控制样式 7.触发器 1.引言 样式(Style),主要是用来让元素或内容呈现一定外观的属性.WPF中 ...
- English trip -- Review Unit2 At school 在学校
What do you need,Loki? I need an eraser What does he need? He needs a dictionary Where's my pencil? ...
- 20170706pptVBA演示文稿批量删除图片
Public Sub StartRecursionFolder() Dim Pre As Presentation Dim FolderPath As String Dim pp As String ...
- hdoj2476 String painter
题意:有一刷子,能将区间内涂成同一字母.给出src,dst串,问最少涂几次? 用dp[i][j]表示区间[i,j]内最少涂的次数.len=1,2时很明显.len=3时,dp[i][j]要么就在dp[i ...
- Strip CodeForces - 487B (单调队列)
题面: Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Ale ...
- php 浮点数
$num = 10.4567; //第一种:利用round()对浮点数进行四舍五入 echo round($num,2); //10.46 //第二种:利用sprintf格式化字符串 $format_ ...
- 『cs231n』作业2选讲_通过代码理解Dropout
Dropout def dropout_forward(x, dropout_param): p, mode = dropout_param['p'], dropout_param['mode'] i ...
- HDU 4764 Stone (巴什博弈)
题意 Tang和Jiang玩石子游戏,给定n个石子,每次取[1,k]个石子,最先取完的人失败,Tang先取,问谁是赢家. 思路 比赛的时候想了不久,还WA了一次= =--后来看题解才发现是经典的巴什博 ...
- windows下面使用nginx配置web注意问题
1.路径一定要用两个反斜杠进行转义,如果只用单个反斜杠,遇到\n就识别不到路径了,例如下图中的\news中包含\n