• 南昌大学航天杯第二届程序设计竞赛校赛网络同步赛 F


    链接:https://www.nowcoder.com/acm/contest/122/F
    来源:牛客网

    题目描述

    阿汤同学最近刚学数论,他发现数论实在是太有趣了,于是他想让你也感受一下数论的乐趣。现在他给你一个正整数 N 和一个正整数 M,要求你用 N 对 M 进行取余操作,即 N % M,记余数为 S。
    但是他发现这样好像并不能让你感受到数论的乐趣,于是他想让你在N 对 M 取余操作的基础上再求出这个余数 S 能分解出多少个不同质因数。

    质因数:质因数在数论里是指能整除给定正整数的质数,质数就是只能整除 1 和本身的数,定义 2 是最小的质数。

    输入描述:

    从标准输入读入数据。
    输入包含多组数据,第一行一个整数 T 代表数据组数。接下来依
    次描述每组数据,对于每组数据:
    第一行输入正整数 N,第二行输入正整数 M

    【数据规模】
    1≤N≤10^100
    1≤M≤2^31-1

    输出描述:

    输出到标准输出。
    对于每组数据,输出一行:
    余数 S 能分解出的不同质因数的个数。
    示例1

    输入

    2
    68
    40
    6
    180

    输出

    2
    2
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    using namespace std;
    #define MAXN 2001000
    #define PSIZE 100000
    int a[PSIZE],b[PSIZE];
    int plist[PSIZE], pcount=0;
    int prime(int n){
            int i;
            if ((n!=2&&!(n%2))||(n!=3&&!(n%3))||(n!=5&&!(n%5))||(n!=7&&!(n%7)))
                    return 0;
            for (i=0;plist[i]*plist[i]<=n;++i)
                    if (!(n%plist[i]))
                            return 0;
            return n>1;
    }
    void initprime(){
            int i;
            for (plist[pcount++]=2,i=3;i<100000;++i)
                    if (prime(i))
                            plist[pcount++]=i;
    }
    int prime_factor(int n, int* f, int *nf) {
            int cnt = 0;
            int n2 = sqrt((double)n);
            for(int i = 0; n > 1 && plist[i] <= n2; ++i)
                    if (n % plist[i] == 0) {
                            for (nf[cnt] = 0; n % plist[i] == 0; ++nf[cnt], n /= plist[i]);
                            f[cnt++] = plist[i];
                    }
            if (n > 1) nf[cnt] = 1, f[cnt++] = n;
            return cnt;
    }
    int main(){
        int t;
        string s;
        int n;
    
        initprime();
        while(cin>>t){
            while(t--){
                cin>>s>>n;
                int ans=0;
                int len = s.length();
                for (int i = 0; i<len; i++){
                    ans = (int)(((long long)ans * 10 + s[i] - '0') % n);
                }
                cout<<prime_factor(ans,a,b)<<endl;
    
            }
        }
    }
  • 相关阅读:
    [王爽汇编语言笔记]内存地址空间
    [zt]Tutorial: Make Vim as Your C/C++ IDE Using c.vim Plugin
    ubuntu下root 密码忘记的解决方法
    脱壳
    远程访问linux服务器
    【自己动手写操作系统学习笔记】1.hello world!
    不会溢出的除法
    javascript 数据类型和值(基础版)
    WebService 使用的简单例子
    SQL group by 和 having
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/9063335.html
Copyright © 2020-2023  润新知