HDOJ 4473 Exam 暴力枚举
2015-09-02 13:57
405 查看
所求的既 a*b*c<=n 的对数.....
暴力枚举a,b根据c计算结果
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1316 Accepted Submission(s): 559
Problem Description
Rikka is a high school girl suffering seriously from Chūnibyō (the age of fourteen would either act like a know-it-all adult, or thinks they have special powers no one else has. You might google it for detailed explanation) who, unfortunately, performs badly
at math courses. After scoring so poorly on her maths test, she is faced with the situation that her club would be disband if her scores keeps low.
Believe it or not, in the next exam she faces a hard problem described as follows.
Let’s denote f(x) number of ordered pairs satisfying (a * b)|x (that is, x mod (a * b) = 0) where a and b are positive integers. Given a positive integer n, Rikka is required to solve for f(1) + f(2) + . . . + f(n).
According to story development we know that Rikka scores slightly higher than average, meaning she must have solved this problem. So, how does she manage to do so?
Input
There are several test cases.
For each test case, there is a single line containing only one integer n (1 ≤ n ≤ 1011).
Input is terminated by EOF.
Output
For each test case, output one line “Case X: Y” where X is the test case number (starting from 1) and Y is the desired answer.
Sample Input
1
3
6
10
15
21
28
Sample Output
Case 1: 1
Case 2: 7
Case 3: 25
Case 4: 53
Case 5: 95
Case 6: 161
Case 7: 246
Source
2012 Asia Chengdu Regional Contest
/* ***********************************************
Author :CKboss
Created Time :2015年09月02日 星期三 12时42分31秒
File Name :HDOJ4473.cpp
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef unsigned long long int LL;
LL n;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int cas=1;
while(scanf("%lld",&n)!=EOF)
{
LL ans=0;
for(LL a=1;a*a<=n;a++)
{
for(LL b=a;b*b*a<=n;b++)
{
LL c=n/(a*b);
LL ret=0LL;
if(a==b) ret+=1LL;
else ret+=3LL;
if(c>b) { if(a==b) ret+=3LL*(c-b); else ret+=6LL*(c-b); }
ans+=ret;
}
}
printf("Case %d: %lld\n",cas++,ans);
}
return 0;
}
暴力枚举a,b根据c计算结果
Exam
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1316 Accepted Submission(s): 559
Problem Description
Rikka is a high school girl suffering seriously from Chūnibyō (the age of fourteen would either act like a know-it-all adult, or thinks they have special powers no one else has. You might google it for detailed explanation) who, unfortunately, performs badly
at math courses. After scoring so poorly on her maths test, she is faced with the situation that her club would be disband if her scores keeps low.
Believe it or not, in the next exam she faces a hard problem described as follows.
Let’s denote f(x) number of ordered pairs satisfying (a * b)|x (that is, x mod (a * b) = 0) where a and b are positive integers. Given a positive integer n, Rikka is required to solve for f(1) + f(2) + . . . + f(n).
According to story development we know that Rikka scores slightly higher than average, meaning she must have solved this problem. So, how does she manage to do so?
Input
There are several test cases.
For each test case, there is a single line containing only one integer n (1 ≤ n ≤ 1011).
Input is terminated by EOF.
Output
For each test case, output one line “Case X: Y” where X is the test case number (starting from 1) and Y is the desired answer.
Sample Input
1
3
6
10
15
21
28
Sample Output
Case 1: 1
Case 2: 7
Case 3: 25
Case 4: 53
Case 5: 95
Case 6: 161
Case 7: 246
Source
2012 Asia Chengdu Regional Contest
/* ***********************************************
Author :CKboss
Created Time :2015年09月02日 星期三 12时42分31秒
File Name :HDOJ4473.cpp
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef unsigned long long int LL;
LL n;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int cas=1;
while(scanf("%lld",&n)!=EOF)
{
LL ans=0;
for(LL a=1;a*a<=n;a++)
{
for(LL b=a;b*b*a<=n;b++)
{
LL c=n/(a*b);
LL ret=0LL;
if(a==b) ret+=1LL;
else ret+=3LL;
if(c>b) { if(a==b) ret+=3LL*(c-b); else ret+=6LL*(c-b); }
ans+=ret;
}
}
printf("Case %d: %lld\n",cas++,ans);
}
return 0;
}
相关文章推荐
- linux/unix下对指定大小的文件进行批量压缩
- Webvan之死----基于用户假设的产品开发与扩张
- 51nod1007:正整数分组 DP
- 【BLE】CC2541之广播MAC
- split的几个问题
- 【css杂记】css兼容处理杂记 1
- java面试总结2
- Nginx 在window server 2008R2上装有IIS启动不了
- 【css杂记】css兼容处理杂记 1
- 51nod1007:正整数分组 DP
- Gradle 用法总结
- HDU 1710(Binary Tree Traversals)二叉树的遍历
- opencv我的单通道阈值分割
- Android Buledroid (一) 蓝牙简介
- iOS计算缓存文件的大小
- Java面试总结1
- 集成环信:Warning! ivar size mismatch in PSUICollectionView_ - can't change the superclass.解决办法
- 完美解决“The identity used to sign the executable is no longer valid.”问题
- Autoit3 脚本编写举例
- An Overview of RMI Applications