2019暑假个人排位集训补题--数学题

URAL2102 Michael and Cryptography (分解质因数)

https://vjudge.net/problem/URAL-2102
The hacker Michael develops breakthrough password manager, which is called KEK (Keeper of Encrypted Keys). A distinctive feature of KEK is excellent security. To achieve this, Michael had to develop innovative encryption scheme. For example, in the well-known RSA scheme the sum of prime powers in the factorization is equal to 2, whereas in Michael’s scheme this sum is equal to 20!
However, the current version of the KEK runs very slow. Michael has found out that the problem is in the function of checking a modulus for correctness. This function should take the number n and answer, whether the sum of prime powers included in the factorization of n is equal to 20. Can you do this quickly?
Remember that the factorization of an integer is the representation of it in the form like p 1 α1 · p 2 α2 · … · p k αk, where p i are prime numbers, and α i > 0. It is known that such representation is unique. Then the sum of powers looks like α 1 + α 2 + … + α k.
Input
The only line contains an integer n (1 ≤ n ≤ 10 18).
Output
If the sum of prime powers, included in the factorization of n, is equal to 20, then output “Yes”, otherwise output “No”.
Example

inputoutput
2No
1048576Yes
10000000000Yes

题意:分解一个数,把他分解为质数乘积使每个质数的个数加起来总和为20

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
int main()
{
    long long n;
    int cnt=0;
    scanf("%lld",&n);
    if(n==1)printf("No");
    else
    {
        int flag=1;
    for(ll i=2;i*i<=n;i++)
    {
        if(cnt>20||(ll)pow(i,20-cnt)>n)
        {
            flag=0;
            break;
        }
        while(n%i==0)
        {
            cnt++;
            n/=i;
        }
    }
    if(!flag)
    {
        printf("No");
        return 0;
    }
    if(flag&&n!=1)cnt++;
    if(cnt==20)printf("Yes");
    else printf("No");
    }
    return 0;
}

CodeChef - STFM Chef and Strange Formula (康托展开)

https://cn.vjudge.net/problem/CodeChef-STFM
中文题面:https://vj.ti12z.cn/6710047a10fbc6b648c6ec52355e06de?v=1562604395

For positive integer x let define function F(x) = 1 * (1! + x) + 2 * (2! + x) + … + x * (x! + x).

“k!” means factorial: k! = 1 * 2 * … * k

Chef wants to calculate F(p1) + F(p2) + … + F(pn).

As answer could be large, help him, calculate value modulo m.

Input
First line contains two integers n and m.
Next line contains n space separated integers pi.
Output
Output a single line containing one integer — calculated value modulo m.
Constraints
1 ≤ n ≤ 105
1 ≤ pi ≤ 1018
1 ≤ m ≤ 107
Subtasks
Subtask #1: 1 ≤ pi ≤ 6 (10 points)
Subtask #2: 1 ≤ pi ≤ 7 * 103 (25 points)
Subtask #3: m - prime number (25 points)
Subtask #4: original constraints (40 points)
Example
Input:
5 7
1 2 3 4 5

Output:
6

Explanation

F(1) = 1 * (1! + 1) = 2

F(2) = 1 * (1! + 2) + 2 * (2! + 2) = 3 + 8 = 11

F(3) = 1 * (1! + 3) + 2 * (2! + 3) + 3 * (3! + 3) = 4 + 10 + 27 = 41

F(4) = 1 * (1! + 4) + 2 * (2! + 4) + 3 * (3! + 4) + 4 * (4! + 4) = 5 + 12 + 30 + 112 = 159

F(5) = 1 * (1! + 5) + 2 * (2! + 5) + 3 * (3! + 5) + 4 * (4! + 5) + 5 * (5! + 5) = 794

F(1) + F(2) + F(3) + F(4) + F(5) = 2 + 11 + 41 + 159 + 794 = 1007

1007 modulo 7 = 6

思路:
康托展开X=a[n]∗(n−1)!+a[n−1]∗(n−2)!+…+a[i]∗(i−1)!+…+a[1]∗0!X=a[n]∗(n−1)!+a[n−1]∗(n−2)!+…+a[i]∗(i−1)!+…+a[1]∗0!
在这里插入图片描述
那么对照一下题目里的公式:

F(x)=1∗1!+2∗2!+3∗3!+…+x∗x!+(1+2+3…+x)∗xF(x)=1∗1!+2∗2!+3∗3!+…+x∗x!+(1+2+3…+x)∗x
在这里插入图片描述
后面的和大家都会算。

前面就是序列
x+1,x,x−1,…,2,1x+1,x,x−1,…,2,1 的康托展开。

显然x+1个元素的排列为(x+1)!,因为是从0开始计算,所以上面这个排列的康托展开就是(x+1)!−1
所以

可以发现,阶乘部分当n>m的部分%m后是肯定=0的
↓代码错的 还需修改

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

typedef long long ll;
const int N=1e7+7;
int f[N];
int main()
{
    ll n,m,ans=0,p;
    cin>>n>>m;
    f[0]=1;
    for(int i=1;i<=m;i++)f[i]=(f[i-1]*1LL*i)%m;
    for(int i=0;i<n;i++)
    {
        ll tmpAns=0;
        scanf("%lld",&p);
        if(p&1)tmpAns=(p*(((p%m)*((p+1)/2)%m)%m))%m;//判断p的奇偶,奇数则如此,否则如下
        else
            tmpAns=((p%m)*((((p>>1)%m)*((p+1)%m))%m))%m;
        ll fac;
        if(p+1>=m)fac=0;
        else fac=f[p+1];
        tmpAns=(tmpAns+fac-1)%m;
        ans=(ans+tmpAns)%m;
    }
    cout<<ans<<endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
旅游社交小程序功能有管理员和用户。管理员有个人中心,用户管理,每日签到管理,景点推荐管理,景点分类管理,防疫查询管理,美食推荐管理,酒店推荐管理,周边推荐管理,分享圈管理,我的收藏管理,系统管理。用户可以在微信小程序上注册登录,进行每日签到,防疫查询,可以在分享圈里面进行分享自己想要分享的内容,查看和收藏景点以及美食的推荐等操作。因而具有一定的实用性。 本站后台采用Java的SSM框架进行后台管理开发,可以在浏览器上登录进行后台数据方面的管理,MySQL作为本地数据库,微信小程序用到了微信开发者工具,充分保证系统的稳定性。系统具有界面清晰、操作简单,功能齐全的特点,使得旅游社交小程序管理工作系统化、规范化。 管理员可以管理用户信息,可以对用户信息添加修改删除。管理员可以对景点推荐信息进行添加修改删除操作。管理员可以对分享圈信息进行添加,修改,删除操作。管理员可以对美食推荐信息进行添加,修改,删除操作。管理员可以对酒店推荐信息进行添加,修改,删除操作。管理员可以对周边推荐信息进行添加,修改,删除操作。 小程序用户是需要注册才可以进行登录的,登录后在首页可以查看相关信息,并且下面导航可以点击到其他功能模块。在小程序里点击我的,会出现关于我的界面,在这里可以修改个人信息,以及可以点击其他功能模块。用户想要把一些信息分享到分享圈的时候,可以点击新增,然后输入自己想要分享的信息就可以进行分享圈的操作。用户可以在景点推荐里面进行收藏和评论等操作。用户可以在美食推荐模块搜索和查看美食推荐的相关信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值