TOJ-1203 Factoring Large Numbers

One of the central idea behind much cryptography is that factoring large numbers is computationally intensive. In this context one might use a 100 digit number that was a product of two 50 digit prime numbers. Even with the fastest projected computers this factorization will take hundreds of years.

You don‘t have those computers available, but if you are clever you can still factor fairly large numbers.

Input

The input will be a sequence of integer values, one per line, terminated by a
negative number. The numbers will fit in gcc‘s long long int datatype.

Output

Each positive number from the input must be factored and all factors (other
than 1) printed out. The factors must be printed in ascending order with 4
leading spaces preceding a left justified number, and followed by a single blank
line.

Sample Input

90
1234567891
18991325453139
12745267386521023
-1

Sample Output

    2
    3
    3
    5

    1234567891

    3
    3
    13
    179
    271
    1381
    2423

    30971
    411522630413

Source: Waterloo
Local Contest Sep. 28, 1996

分解因式。

#include <stdio.h>
int main(){
    long long i,n;
    while(~scanf("%lld",&n) && n>=0){
        for(i=2 ; n>1 ;){
            if(n%i == 0){
                printf("    %lld\n",i);
                n/=i;
            }
            else{
                i++;
                if(i*i>n){
                    printf("    %lld\n",n);
                    break;
                }
            }
        }
        printf("\n");
    }
    return 0;
}  
时间: 2024-10-27 18:08:28

TOJ-1203 Factoring Large Numbers的相关文章

TOJ 1203: Number Sequence

1203: Number Sequence Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte Total Submit: 957            Accepted:208 Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Gi

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************

BNUOJ 19297 Code Refactoring

Code Refactoring Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 1087964-bit integer IO format: %lld      Java class name: Main Problem BCode RefactoringTime Limit: 2 seconds "Harry, my dream is a code waiti

Microsoft SQL Server Version List(SQL Server 版本)

原帖地址 What version of SQL Server do I have? This unofficial build chart lists all of the known Service Packs (SP), Cumulative Updates (CU), patches, hotfixes and other builds of MS SQL Server 2014, 2012, 2008 R2, 2008, 2005, 2000, 7.0, 6.5 and 6.0 tha

javascript 大数值数据运算

javascript数字运算结果不准确: 1.浮点型数字进行运算时,基本四则运算结果都可能不准确,一般是把浮点型数据转换为整型运算,然后在还原处理. 这种情况下可以用一些常用转换方法计算,如下: 1 /** 2 * 加法运算 3 */ 4 function numAdd(num1, num2) { 5 var baseNum, baseNum1, baseNum2; 6 try { 7 baseNum1 = num1.toString().split(".")[1].length; 8

Internet protocol optimizer

A method for optimizing the throughput of TCP/IP applications by aggregating user application data and consolidating multiple TCP/IP connection streams into a single optimized stream for delivery to a destination application. Optimization of the inte

[SinGuLaRiTy] COCI 2011~2012 #2

[SinGuLaRiTy-1007] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 测试题目 对于所有的题目:Time Limit:1s  |  Memory:256 MB 第一题:考试得分(score)[najboljih] [题目描述] 某单位举办了一次考试,考试有8道题,每道题的得分不一样.选手可以随便做,但最后只统计5道题的得分.现在给出选手每道题的得分,求出他最后的得分最大是多少? [输入] 8行,每行一个正整数X(0<=X<

A web crawler design for data mining

Abstract The content of the web has increasingly become a focus for academic research. Computer programs are needed in order to conduct any large-scale processing of web pages, requiring the use of a web crawler at some stage in order to fetch the pa