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

#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. grunt切换下载源

    nrm 是一个 NPM 源管理器,允许你快速地在NPM 源间切换: 安装:npm install -g nrm 列出可选源:nrm ls 切换:nrm use taobao 测试所有源连接时间:nrm ...

  2. Stack trace对性能的影响

    package ceshi; public class ExceptionTest { public long maxLevel = 20; public static void main(Strin ...

  3. 帝国cms本地搬家到服务器文章路径问题?

    由于我的服务器不支持采集功能,我只能选择先在本地采集好文章发布于本地,再打算同步于服务器. 按照官方的做法, 1.先进后台备份了网站的所有数据,系统——备份与恢复数据——备份数据 2.将e\admin ...

  4. (C#)Windows Shell 外壳编程系列8 - 同后缀名不同图标?

    原文 (C#)Windows Shell 外壳编程系列8 - 同后缀名不同图标? (本系列文章由柠檬的(lc_mtt)原创,转载请注明出处,谢谢-) 接上一节:(C#)Windows Shell 外壳 ...

  5. android天气查询(二)之网络json数据的获取

    前面一篇文章介绍了如何使用ksoap获取天气信息,但是使用的网络资源受到了限制,所以我们这里会采用第二种方法,可以无限制的获取.http://m.weather.com.cn/data/1010101 ...

  6. perl5 第十二章 Perl5中的引用/指针

    第十二章 Perl5中的引用/指针 by flamephoenix 一.引用简介二.使用引用三.使用反斜线(\)操作符四.引用和数组五.多维数组六.子程序的引用  子程序模板七.数组与子程序八.文件句 ...

  7. HDU - 2276 Kiki &amp; Little Kiki 2

    Description There are n lights in a circle numbered from 1 to n. The left of light 1 is light n, and ...

  8. C#中类的运用(Eighth day)

    又到了总结知识的时刻了,今天在云和学院学习了类的运用,下面是今天所学知识的总结: 理论: 类的定义语法: [访问修饰符] class 类名 { 成员;  // 1.通过字段来描述类别信息的变量 ... ...

  9. runtime的概念,message send如果寻找不到相应的对象,如何进行后续处理

    运行时刻是指一个程序在运行(或者在被执行)的状态.也就是说,当你打开一个程序使它在电脑上运行的时候,那个程序就是处于运行时刻.在一些编程语言中,把某些可以重用的程序或者实例打包或者重建成为“运行库”. ...

  10. BZOJ 4260: Codechef REBXOR( trie )

    求出前缀和, 那么以第x个元素结尾的最大异或值是max(sumx^sump)(1≤p<x), 用trie加速. 后缀同理, 然后扫一遍就OK了.时间复杂度O(31N) ------------- ...