zoukankan      html  css  js  c++  java
  • ural 1049. Brave Balloonists

    1049. Brave Balloonists

    Time limit: 2.0 second
    Memory limit: 64 MB
     
    Ten mathematicians are flying on a balloon over the Pacific ocean. When they are crossing the equator they decide to celebrate this event and open a bottle of champagne. Unfortunately, the cork makes a hole in the balloon. Hydrogen is leaking out and the balloon is descending now. Soon it will fall into the ocean and all the balloonists will be eaten by hungry sharks.
    But not everything is lost yet. One of the balloonists can sacrifice himself jumping out, so that his friends would live a little longer. Only one problem still exists: who is the one to get out. There is a fair way to solve this problem. First, each of them writes an integer ai not less than 1 and not more than 10000. Then they calculate the magic number N that is the number of positive divisors of the product a1*a2*…*a10. For example, the number of positive integer divisors of 6 is 4 (they are 1,2,3,6). The hero (a mathematician who will be thrown out) is determined according to the last digit of N. Your task is to find this digit.

    Input

    Input contains ten integer numbers (each number is in separate line).

    Output

    Output a single digit from 0 to 9 — the last digit of N.

    Sample

    inputoutput
    1
    2
    6
    1
    3
    1
    1
    1
    1
    1
    
    9
    

    Problem Author: Stanislav Vasilyev
    Problem Source: Ural State University collegiate programming contest (25.03.2000)

    题目大意:求10个数积因子的个数,输出最后一个数字

    思路:

    n = ap1*bp2*cp3 ,a b, c 为质数

    n因子的个数为 (1+p1)*(1+p2)*(1+p3)

    单个分解每个数, 最后用公式。。

    #include <iostream>
    #include <sstream>
    #include <fstream>
    #include <string>
    #include <vector>
    #include <deque>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    #include <algorithm>
    #include <functional>
    #include <utility>
    #include <bitset>
    #include <cmath>
    #include <cstdlib>
    #include <ctime>
    #include <cstdio>
    #include <cstring>
    #define FOR(i, a, b)  for(int i = (a); i <= (b); i++)
    #define RE(i, n) FOR(i, 1, n)
    #define FORP(i, a, b) for(int i = (a); i >= (b); i--)
    #define REP(i, n) for(int i = 0; i <(n); ++i)
    #define SZ(x) ((int)(x).size )
    #define ALL(x) (x).begin(), (x.end())
    #define MSET(a, x) memset(a, x, sizeof(a))
    using namespace std;
    
    
    typedef long long int ll;
    typedef pair<int, int> P;
    int read() {
        int x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9') {
            if(ch=='-')f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9') {
            x=x*10+ch-'0';
            ch=getchar();
        }
        return x*f;
    }
    const double pi=3.14159265358979323846264338327950288L;
    const double eps=1e-6;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    const int MAXN = 10005;
    const int xi[] = {0, 0, 1, -1};
    const int yi[] = {1, -1, 0, 0};
    
    int N, T;
    int a[MAXN], cnt, prime[MAXN];
    void init() {
        cnt = 0;
        for(int i = 2; i <= 10000; i++) {
            int flag = 1;
            for(int j = 2; j*j <= i; j++) {
                if(i%j == 0) {
                    flag = 0;
                    break;
                }
            }
            if(flag) prime[++cnt] = i;
        }
    }
    int main() {
        //freopen("in.txt", "r", stdin);
        init();
        memset(a, 0, sizeof(a));
        int N = 1, M;
        for(int i = 0; i < 10; i++) {
            scanf("%d", &N);
            for(int j = 1; j <= cnt; j++) {
                // printf("%I64d
    ", N);
                while(N%prime[j] == 0 && N > 1) {
                    N /= prime[j];
                    a[j]++;
                }
            }
        }
        int s = 1;
        for(int i = 1; i <= cnt; i++) {
            s = s*(a[i]+1)%10;
        }
        printf("%d
    ", s);
        return 0;
    }
  • 相关阅读:
    js获取当前页面url网址等信息
    jQuery 复选框全选/取消全选/反选
    js获取日期实例之昨天今天和明天、后天
    mysql不重启修改参数变量
    php 读取功能分割大文件实例详解
    php批量删除数据库下指定前缀的表
    PHP遍历目录返回统计目录大小实例
    PHP二维数组如何根据某个字段排序
    PHP 如何获取二维数组中某个key的集合(高性能查找)
    jQuery 隐藏与显示 input 默认值
  • 原文地址:https://www.cnblogs.com/cshg/p/5893068.html
Copyright © 2011-2022 走看看