只要很朴素的分解就可以了,数据量不大

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <stack>
#include <algorithm> #define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXSIZE = ;
ll n;
stack <int> s; void init_prim(){
memset(visit, true, sizeof(visit));
int num = ;
for (int i = ; i <= nn; ++i){
if (visit[i] == true){
num++;
prime[num] = i;
}
for (int j = ; ((j <= num) && (i * prime[j] <= nn)); ++j){
visit[i * prime[j]] = false;
if (i % prime[j] == ) break; //点睛之笔
}
}
} ll quickpow(ll m,ll n,ll k){
int b = ;
while (n > ){
if (n & )
b = (b*m)%k;
n = n >> ;
m = (m*m)%k;
}
return b;
} ll getsum(int x){
int sum = ;
while(x){
sum += x % ;
x = x / ;
}
return sum;
} bool witness(ll a,ll n){
ll t,d,x;
d = ;
int i=ceil(log(n-1.0)/log(2.0)) - ;//j
for(;i>=;i--)
{
x=d; d=(d*d)%n;
if(d== && x!= && x!=n-) return true;
if( ((n-) & (<<i)) > )
d=(d*a)%n;
}
return d==? false : true;
}
bool miller_rabin(ll n){
int s[]={,,};
if(n== || n == ) return true;
if(n== || ((n&)==)) return false;
for(int i=;i<;i++)//
if(witness(s[i], n)) return false;
return true;
} bool isPrime(ll n){
if(n == || n == || n == || n == ) return true;
else if(n % == || n % == || n % == ) return false;
for(int i = ; i <= sqrt(n); ++i){
if(n % i == ) return false;
}
return true;
} bool judge(ll x){
int sum1, sum2 = , i;
sum1 = getsum(x);
for(i = ; i <= sqrt(x); ++i){
if(x % i == ){
s.push(i);
x = x / i;
while(x % i == ){
s.push(i);
x = x / i;
}
}
if(x == )
break;
}
if(x > ) s.push(x);
while(!s.empty()){
sum2 += getsum(s.top());
s.pop();
}
if(sum1==sum2) return true;
else return false;
}
int main(){
int i, j, k;
while(cin >> n){
if(n <= ) break;
ll num = n;
while(){
++num;
if(isPrime(num)) continue;
else if(judge(num)){
cout << num << endl;
break;
}
}
}
return ;
}

POJ 1142 质因数分解的更多相关文章

  1. POJ 1845 Sumdiv#质因数分解+二分

    题目链接:http://poj.org/problem?id=1845 关于质因数分解,模板见:http://www.cnblogs.com/atmacmer/p/5285810.html 二分法思想 ...

  2. POJ 2429 long long 质因数分解

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16206   Accepted: ...

  3. poj 3421 X-factor Chains——质因数分解

    题目:http://poj.org/problem?id=3421 记忆化搜索竟然水过去了.仔细一想时间可能有点不对,但还是水过去了. #include<iostream> #includ ...

  4. Poj 1401 Factorial(计算N!尾数0的个数——质因数分解)

    一.Description The most important part of a GSM network is so called Base Transceiver Station (BTS). ...

  5. POJ 1142 Smith Numbers(史密斯数)

    Description 题目描述 While skimming his phone directory in 1982, Albert Wilansky, a mathematician of Leh ...

  6. poj 1811 大数分解

    模板 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> ...

  7. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  8. 求n!质因数分解之后素数a的个数

    n!质因数分解后P的个数=n/p+n/(p*p)+n/(p*p*p)+......直到n<p*p*p*...*p //主要代码,就这么点东西,数学真是厉害啊!幸亏我早早的就退了数学2333 do ...

  9. AC日记——质因数分解 1.5 43

    43:质因数分解 总时间限制:  1000ms 内存限制:  65536kB 描述 已知正整数 n 是两个不同的质数的乘积,试求出较大的那个质数. 输入 输入只有一行,包含一个正整数 n. 对于60% ...

随机推荐

  1. [LeetCode]题解(python):006-ZigZag Conversion

    题目来源: https://leetcode.com/problems/zigzag-conversion/ 题意分析: 这道题目是字符串处理的题目.输入一个字符串和一个数字,将字符串填入倒Z形输入字 ...

  2. night Mode 夜间模式css

    *,*:before,*:after,html[mode='nightmode'] * { color: #61615f !important; border-color: #212a32 !impo ...

  3. 【转】AC算法详解

    原文转自:http://blog.csdn.net/joylnwang/article/details/6793192 AC算法是Alfred V.Aho(<编译原理>(龙书)的作者),和 ...

  4. Qt实现16进制unicode转utf-8以及国际音标编码问题

    由于项目需要,需要对网络资源进行解码.遇到编码问题.研究了下基本编码原理.于是有了下面两个通用代码 1. 16进制unicode转换为utf-8中文显示 QString unicodeToUtf_8( ...

  5. 在OSX狮子(Lion)上安装MYSQL(Install MySQL on Mac OSX)

    这篇文章简述了在Mac OSX狮子(Lion)上安装MySQL Community Server最新版本v10.6.7的过程. MySQL是最流行的开源数据库管理系统.首先,从MySQL的下载页面上下 ...

  6. MVC 优缺点

    MVC是一个架构,或者说是一个设计模式,它就是强制性使应用程序的输入,处理和输出分开.将一个应用程序分为三个部分:Model,View,Controller. 1. MVC的优点 (1) 可以为一个模 ...

  7. 用Mediawiki做百科网站资源大参考

    MediaWiki简易安装教程**关于mediawiki 一些好的资料: http://codex.wordpress.org.cn/Mediawiki%E5%BB%BA%E7%AB%99%E7%BB ...

  8. Oracle 使用RMAN

    RMAN 数据库备份 特点: . 跳过未使用的数据块 . 备份压缩 . 执行增量备份 . 块级别的恢复 组件: . RMAN命令执行器(RMAN Executable) . 目标数据库(Traget ...

  9. android程序报错“error launching activity com.android.ddmlib.shellcommandunresponsiveexception”的解决方式

    今天在调试android程序的时候,因为是NDK开发,要先编译.so库再打包下载到android模拟器,所以花费的时间比較长.控制台就会报例如以下错误: error launching activit ...

  10. Oracle 创建用户并且授权

    以sysdba登陆 创建用户:CREATE USER username IDENTIFIED BY password; 授予(角色)权限:GRANT CONNECT,RESOURCE TO usern ...