Mathematically some problems look hard. But with the help of the computer, some problems can be easily solvable.
In this problem, you will be given two integers a and b. You have to find the summation of the scores of the numbers from a to b (inclusive). The score of a number is defined as the following function.
score (x) = n2, where n is the number of relatively prime numbers with x, which are smaller than x
For example,
For 6, the relatively prime numbers with 6 are 1 and 5. So, score (6) = 22 = 4.
For 8, the relatively prime numbers with 8 are 1, 3, 5 and 7. So, score (8) = 42 = 16.
Now you have to solve this task.
Input starts with an integer T (≤ 105), denoting the number of test cases.
Each case will contain two integers a and b (2 ≤ a ≤ b ≤ 5 * 106).
For each case, print the case number and the summation of all the scores from a to b.
3
6 6
8 8
2 20
Case 1: 4
Case 2: 16
Case 3: 1237
Euler’s totient function applied to a positive integer n is defined to be the number of positive integers less than or equal to n that are relatively prime to n. is read “phi of n.”
Given the general prime factorization of , one can compute using the formula
---------------------------------------分割线------------------------------------------------------------------------------------
求a,b内所有数的欧拉函数的平方和
由于T比较大,且a,b范围较大,所以考虑用预处理的方式O(1)查询
直接用LL存前缀和会炸LL,所以必须用unsigned LL,而且欧拉函数平方的时候也要转为ULL。
--------------------------------分割线-------------------------------------------------------------------------------------------
#include
#define __bug(x) cout<<"test:"<>T;
// __bug(res[1]);
for(int cas=1; cas<=T; cas++)
{
int a,b;
cin>>a>>b;
printf("Case %d: %llu\n",cas,pre[b]-pre[a-1]);
}
return 0;
}
-----------------------------------------分割线----------------------------------------------------------------------------------
I have an Ifter party at the 5th day of Ramadan for the contestants. For this reason I have invited C contestants and arranged P piaju’s (some kind of food, specially made for Ifter). Each contestant ate Q piaju’s and L piaju’s were left (L < Q).
Now you have to find the number of piaju’s each contestant ate.
Input starts with an integer T (≤ 325), denoting the number of test cases.
Each case contains two non-negative integers P and L (0 ≤ L < P < 231).
For each case, print the case number and the number of possible integers in ascending order. If no such integer is found print ‘impossible’.
4
10 0
13 2
300 98
1000 997
Case 1: 1 2 5 10
Case 2: 11
Case 3: 101 202
Case 4: impossible
-----------------------------------------------------分割线----------------------------------------------------------------------
有p克蛋糕,每人吃q克,剩余l克,问q的值有多少种情况,并从小到大输出。
即求p-l的所有大于l的因数
无(我要是再因为输出里少了空格而WA,我直播吃了电脑)。
---------------------------------------------------分割线------------------------------------------------------------------------
#include
#define __bug(i,x) cout<<"test "<>p>>l;
for(ll i=1;i<=(int)sqrt(p-l);i++)
{
if((p-l)%i==0)
{
if(i>l&&i<=p-l)
ans[cnt++]=i;
if((p-l)/i>l&&(p-l)/i<=p-l&&(p-l)/i!=i)
ans[cnt++]=(p-l)/i;
}
}
sort(ans,ans+cnt,cmp);
printf("Case %d:",cas);
for(int i=0;i
-----------------------------------------------分割线----------------------------------------------------------------------------
In a strange planet there are n races. They are completely different as well as their food habits. Each race has a food-eating period. That means the ith race eats after every xi de-sec (de-sec is the unit they use for counting time and it is used for both singular and plural). And at that particular de-sec they pass the whole day eating.
The planet declared the de-sec as ‘Eid’ in which all the races eat together.
Now given the eating period for every race you have to find the number of de-sec between two consecutive Eids.
Input starts with an integer T (≤ 225), denoting the number of test cases.
Each case of input will contain an integer n (2 ≤ n ≤ 1000) in a single line. The next line will contain n integers separated by spaces. The ith integer of this line will denote the eating period for the ith race. These integers will be between 1 and 10000.
For each case of input you should print a line containing the case number and the number of de-sec between two consecutive Eids. Check the sample input and output for more details. The result can be big. So, use big integer calculations.
2
3
2 20 10
4
5 6 30 60
Case 1: 20
Case 2: 60
-------------------------------------------分割线--------------------------------------------------------------------------------
求n个数的最小公倍数
将n个数分解质因数,记录对于每个质因数的最大值,累乘即可。
因为最小公倍数LL存不下,所以本题的实质是高精度乘单精度。
-------------------------------------------分割线--------------------------------------------------------------------------------
#include
using namespace std;
const double PI=acos(-1.0);
const int N=1e5+5;
int ans[N],len;
void multiply(int fact)
{
for(int i=0; i M;
M.clear();
memset(ans,0,sizeof(ans));
ans[0]=1;
len=1;
int n;
scanf("%d",&n);
while(n--)
{
int x;
scanf("%d",&x);
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
{
int cnt=0;
while(x%i==0)
{
cnt++;
x/=i;
}
M[i]=max(M[i],cnt);
}
}
if(x>=0)
{
M[x]=max(M[x],1);
}
}
map ::iterator it;
for(it=M.begin();it!=M.end();it++)
{
// cout<<"test:"<<(it->first)<<' '<<(it->second)<second);i++)
{
multiply((it->first));
}
}
printf("Case %d: ",cas);
for(int i=len-1;i>=0;i--)
printf("%d",ans[i]);
printf("\n");
}
return 0;
}
----------------------------------------------分割线-----------------------------------------------------------------------------