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;
    }
  • 相关阅读:
    html5 video标签如何禁止视频下载
    Redis源代码-数据结构Adlist双端列表
    HTML5分析实战WebSockets基本介绍
    Chromium on Android: Android在系统Chromium为了实现主消息循环分析
    Android AIDL使用特定的解释
    [LeetCode]Maximum Product Subarray
    OC省字典的数组摘要集
    CocoaChina 第四个测试
    Java在的时候,类定义HashSet初始化方法
    WSHPSRS-匹克选择列表生成器-SRS(R12.2.3)
  • 原文地址:https://www.cnblogs.com/cshg/p/5893068.html
Copyright © 2011-2022 走看看