CodeForces 172 D.Calendar Reform(数论)
来源:互联网 发布:收费网站源码 编辑:程序博客网 时间:2024/05/23 21:26
Description
第一年a天,第二年a+1天,以此类推,第n年a+n-1天,一年可以被分成几个月,一个月的天数必须是完全平方数,一年中每个月的天数相同,问这n天最多有几个月
Input
两个整数a和n(1<=a,n<=1e7,a+n-1<=1e7)
Output
输出最少月数
Sample Input
25 3
Sample Output
30
Solution
问题转化为把a~a+n-1中的每个数拆成a^2*b形式,且b最小,所以把每个数的平方因子全部除掉即可
Code
#include<cstdio>#include<cstring>using namespace std;typedef long long ll;const int maxn=10000001;int a,n,x[maxn];int main(){ scanf("%d%d",&a,&n); for(int i=a;i<=a+n-1;i++)x[i]=i; for(int i=2;i*i<=a+n-1;i++) { int p=i*i; int t=((a+p-1)/p)*p; for(int j=t;j<=a+n-1;j+=p) while(x[j]%p==0)x[j]/=p; } ll ans=0; for(int i=a;i<=a+n-1;i++)ans+=x[i]; printf("%I64d\n",ans); return 0;}
阅读全文
1 0
- CodeForces 172 D.Calendar Reform(数论)
- CodeForces 615 D. Multipliers(数论)
- CodeForces 632D Longest Subsequence(数论)
- CodeForces 735 D.Taxes(数论)
- codeforces 900D Unusual Sequences (数论)
- Codeforces--659E--New Reform(深搜好题)
- codeforces 490D Chocolate 数论
- Codeforces 490D Chocolate(数论)
- CodeForces 735D - Taxes(数论)
- codeforces 490D D. Chocolate(数论)
- codeforces 66 D. Petya and His Friends(数论)
- Codeforces 584D Dima and Lisa(数论)
- Codeforces Round #338 (Div. 2)D-Multipliers(数论)
- codeforces 475D CGCDSSQ (st表+数论)
- Codeforces Round #382 (Div. 2) D Taxes(数论)
- Codeforces Round #422 D. My pretty girl Noora (数论)
- CodeForces 55D Beautiful numbers(数位dp+数论)
- CodeForces 732 F.Tourist Reform(边双连通分量)
- 使用commons-fileupload完成资源向服务器的上传
- (转)C++异或运算和位运算(C的|、||、&、&&、异或、~、!运算)
- 基于阿里云的Jenkins+Maven+SVN+Tomcat的持续集成(二)-tomcat、svn、maven安装
- 快速排序
- DLL中导出ANSI和UNICODE函数
- CodeForces 172 D.Calendar Reform(数论)
- 二叉树
- BZOJ 2152: 聪聪可可 点分治
- windows adb不识别(VID PID更改)
- oracle 错误总结
- android ndk 03 C语言 动态分配内存,字符串操作
- Android aar格式库
- 关于机器学习在线预测的任务学习笔记
- 栈的应用——中缀表达式转后缀表达式,后缀表达式的求值,中缀表达式求值