uva-10879-因数分解
把一个数分解成n*m的形式,一定存在
解题思路:
一个大于1的正整数最小因数一定是素数
ac时间80ms,感觉慢了,可惜看不到0ms的大神代码
#include <iostream>
#include<memory.h>
#include<stdio.h>
using namespace std; const int N = ; int p[N];
int pl = ; void initPrime()
{
memset(p, -, sizeof(p));
int i, j;
for (i = ; i <= N; i++)
{
if (p[i] == -)
p[pl++] = i;
for (j = ; j < pl; j++)
{
if (p[j] * i >= N)
{
break;
}
p[p[j] * i] = ;
if (i % p[j] == )
break;
}
}
}
int main()
{
freopen("d:\\1.txt", "r", stdin);
initPrime();
int n;
int t = ;
int c;
cin >> c;
while (c--)
{
cin >> n;
printf("Case #%d: ", t);
int m, k, j;
for (int i = ; i < pl; i++)
{
if (n % p[i] == )
{
j = i;
break;
}
}
m = p[j];
k = n / m;
cout << n << " = " << m << " * " << k; for (int i = ; i < pl; i++)
{
if (k % p[i] == )
{
j = i;
break;
}
}
m = m * p[j];
k = k / p[j];
cout << " = " << m << " * " << k;
cout << endl;
t++; }
return ;
}
uva-10879-因数分解的更多相关文章
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
- UVA - 10375 Choose and divide[唯一分解定理]
UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
- UVA - 1025 A Spy in the Metro[DP DAG]
UVA - 1025 A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especia ...
随机推荐
- Aho-Corasick算法
2018-03-15 10:25:02 在计算机科学中,Aho–Corasick算法是由Alfred V. Aho和Margaret J.Corasick 发明的字符串搜索算法,用于在输入的一串字符串 ...
- [Checking for libstdc++-4.4.4-13.el6-i686; Not found. Failed] 的解决。
单纯 yum install libstdc++-4.4.4.i686 是不行的. 应该安装 yum install libstdc++-devel.i686 顺带就能装上需要的lib 真够变态的. ...
- bzoj1179: [Apio2009]Atm scc缩点+dag上dp
先把强连通缩点,然后变成了dag,dp求终点是酒吧的最长路即可, /************************************************************** Pro ...
- Lightoj-1220
https://vjudge.net/problem/LightOJ-1220 求x=bp中最大的p,x可能为负数. 因数分解,x=p1x1*p2x2*...*pnxn x=(p1x1'*p2x2'* ...
- powerdesigner安装图解
- 042——VUE中组件之子组件使用$on与$emit事件触发父组件实现购物车功能
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- bzoj1068
题意: 给你一个未压缩串,要求你把它压缩 问你压缩后最小长度 题解: 区间dp 怎么少就怎么来 代码: #include<bits/stdc++.h> using namespace st ...
- 线程互斥,mutex
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- Double H2.0
Double H2.0 https://www.cnblogs.com/wxh9494/p/9879442.html 选题报告 一.项目描述(Project Description) 本项目提供一个公 ...
- 利用javascript:void(0)制作假的提交按钮替代button
在写html页面,我们很自然的在表单提交的地方采用button来作为提交按钮,但是,用<button type=”button”>按钮</button>作为提交代码会有个问题, ...