2017日照夏令营 day6 t1 fac

本文介绍了一种解决阶乘游戏中求得分问题的算法。该问题要求计算在给定n和m的情况下,通过不断除以m直至无法整除的过程中,能够得到的最大得分。算法采用质因数分解的方法,并考虑了当m为合数时的情况。

题目大意:
有一个与阶乘有关的游戏,给出两个整数n ,m ,令t=n!,每轮游戏的流程如下
1.如果 m不能整除t ,即 t mod m !=0 ,跳到第三步;如果能整除,跳到第二步
2.令t=t/m,xyx的得分+1并返回第一步
3.游戏结束
xyx共进行T轮游戏,他想知道每轮他的得分是多少
特别注意,m,n<10e9;

解题思路:
先理解一下题意,其实就是找n中有多少个m,可以先考虑m是质数的情况,发现在n!中,每隔m个数会出现m的倍数,我们只要不停地/m就好了。
那m是合数怎么办? 可以用筛法把m分解质因数,每次记录当前质因数以及它出现的次数,然后每次算出n中有多少个当前质因数,注意因为可能一个质因数出现多次,最后需要再/p,最后取最小值就可以了。

#include<cstdio>
#include<iostream>
using namespace std;
int T,n,m;
int ans;
int cal(int p,int a)//求n中有几a个p
{
    int t=0;
    for (int i=n;i;i/=p) t+=i/p;
    return t/a;
}
main()
{
//  freopen("fac.in","r",stdin);
//  freopen("fac.out","w",stdout);
    cin>>T;
    while(T--)
    {
        scanf("%d%d",&n,&m);
        ans=2e9;
        for (int t,s,i=2;i*i<=m;++i)
            if (m%i==0)
            {
                t=i;s=0;
                while(m%i==0){//筛法分解质因数
                    s++;
                    m/=i;
                }
                ans=min(ans,cal(t,s));
            }
        if (m>1) ans=min(ans,cal(m,1));//因为筛法枚举的是小于等于根号m的质因数,如果分解后m>1,说明有且仅有一个大于根号m的质因数,特判一下。
        printf("%d\n",ans);
    }
}
Summary of Notable New Features in 15.7 •We added support to change installation locations. •You can Save All your pending changes before you start your update. •The update dialog provides you even more details about your update during installation. •C# 7.3 is included in Visual Studio version 15.7. •We improved solution load time for C# and VB projects. •We made numerous updates to F# and its tools, with a focus on performance. •We reduced the time to enable IntelliSense for large .NET Core projects by 25%. •We made Quick Info improvements and new .NET refactorings like convert for-to-foreach and make private fields readonly. •We added the ability to publish ASP.NET Core applications to App Service Linux without containers. •Live Unit Testing works with embedded pdbs and supports projects that use reference assemblies. •The Test Explorer has more responsive icons during test runs. •C++ developers can use CodeLens for unit testing. •We added new rules enforcing items from the C++ Core Guidelines. •Debugging large solutions with /Debug:fastlink PDBs is more robust. •CMake integration supports CMake 3.11 and static analysis. •Python projects support type hints in IntelliSense, and a Run MyPy command has been added to look for typing errors in your code. •Conda environments are supported in Python projects. •We added a next version of our Python debugger based on the popular open source pydevd debugger. •TypeScript 2.8 is included in Visual Studio version 15.7. •We improved Kestrel HTTPs support during debugging. •We added support for JavaScript debugging with Microsoft Edge. •The Debugger supports VSTS and GitHub Authentication for Source Link. •IntelliTrace's step-back debugging feature is supported for debugging .NET Core projects. •We added IntelliTrace support for taking snapshots on exceptions. •We removed the blocking modal dialog from branch checkouts in Git when a solution or project reload is not required. •You have the option to choose between OpenSSL and SChannel in Git. •You can create and associate Azure Key Vaults from within the Visual Studio IDE. •Visual Studio Tools for Xamarin can automatically install missing Android API levels required by Xamarin.Android projects. •The Xamarin.Forms XAML editor provides IntelliSense and quick fixes for conditional XAML. •Visual Studio Build Tools now supports installing into a container, and we added support for building Azure, UWP, and additional project types. •You can create build servers without installing all of Visual Studio. •The Windows 10 April 2018 Update SDK - Build 17134 is the default required SDK for the Universal Windows Platform development workload. •We added support for Visual State Management for all UWP apps and more. •We enabled automatic updates for sideloaded APPX packages. •You have new tools for migrating to NuGet PackageReference. •We added support for NuGet package signatures. •We added Service Fabric Tooling for the 6.2 Service Fabric release. •We updated Entity Framework Tools to work with the EF 6.2 runtime and to improve reverse engineering of existing databases.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值