Just Prog!

Coding with Love & Peace.

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

阅读全文 »

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
P1304 哥德巴赫猜想
https://www.luogu.com.cn/problem/P1304

输入一个偶数 N(N<=10000),验证4~N所有偶数是否符合哥德巴赫猜想:任一大于 2 的偶数都可写成两个质数之和。
如果一个数不止一种分法,则输出第一个加数相比其他分法最小的方案。例如 10 , 10=3+7=5+5,则 10=5+5 是错误答案。
*/

//https://www.luogu.com.cn/record/57347821

#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
bool zs[10001]={0};
for(int o=1;o<=10000;o++){
int z=0;
for(int m=1;m<=o;m++){
if(o%m==0){
z++;
}
}
if(z==2){
zs[o]=1;
}
}
for(int i=4;i<=n;i+=2){
for(int o=2;o<=n;o++){
if(zs[o]==1&&zs[i-o]==1){
cout<<i<<"="<<o<<"+"<<i-o<<endl;
break;
}
}
}
return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//P1075 [NOIP2012 普及组] 质因数分解
//https://www.luogu.com.cn/problem/P1075

//已知正整数 n 是两个不同的质数的乘积,试求出两者中较大的那个质数。

//https://www.luogu.com.cn/record/57292493

#include<iostream>
using namespace std;
int main(){
unsigned long long n;
cin>>n;
for(unsigned long long i=2;i<=n;i++){
if(n%i==0){
cout<<n/i<<endl;
return 0;
}
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
P1179 [NOIP2010 普及组] 数字统计
https://www.luogu.com.cn/problem/P1179

请统计某个给定范围[L,R]的所有整数中,数字 2 出现的次数。

比如给定范围[2,22],数字22 在数 2中出现了 1 次,在数12 中出现 1 次,
在数 20 中出现 1 次,在数 21 中出现 1 次,在数 22 中出现 2 次,所以数字 2 在该范围内一共出现了 6次。
*/

//https://www.luogu.com.cn/record/57239444

#include<iostream>
#include<cmath>
using namespace std;
int main(){
char n[6];
int m;
cin>>m;
int mm=m,mmm;
cin>>mmm;
for(int i=5;i>=0;i--){
if(i!=0){
int nn=m/(pow(10,i)); //pow = ^
n[i]='0'+nn;
m=fmod(m,pow(10,i)); //fmod = %
}else{
n[0]='0'+m;
}
}
int ans=0;
for(int i=mm;i<=mmm;i++){
for(int o=0;o<=5;o++){
if(n[o]>'9'){
n[o]='0';
n[o+1]++;
}
}
for(int o=0;o<=5;o++){
if(n[o]=='2'){
ans++;
}
}
n[0]++;
}
cout<<ans<<endl;
return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*---------------------------------------
P1150 Peter的烟
https://www.luogu.com.cn/problem/P1150
---------------------------------------
Peter 有 n 根烟,他每吸完一根烟就把烟蒂保存起来,
k(k>1)个烟蒂可以换一个新的烟,
那么 Peter 最终能吸到多少根烟呢?
吸烟有害健康。
*/

//https://www.luogu.com.cn/record/56747627

#include<iostream>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
//"此解法为小学4~6年级水平"
//Source: https://www.luogu.com.cn/blog/user37001/solution-p1150
cout<<n+(n-1)/(k-1);
//我上了个假小学(划掉
return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*--------------------------------------------/
P1152 欢乐的跳
https://www.luogu.com.cn/problem/P1152
/--------------------------------------------*/

/*
一个nn个元素的整数数组,如果数组两个连续元素之间差的绝对值包括了[1,n−1]之间的所有整数,则称之符合“欢乐的跳”,
如数组1 4 2 31423符合“欢乐的跳”,因为差的绝对值分别为:3,2,1。
给定一个数组,你的任务是判断该数组是否符合“欢乐的跳”。
*/

//https://www.luogu.com.cn/record/56288145
//https://www.luogu.com.cn/record/56342830

#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
long long int nn[1000];
cin>>n;
for(int i=0;i<n;i++){
cin>>nn[i];
}

bool nnn[1000]={0};
for(int i=0;i<n-1;i++){
int h=abs(nn[i]-nn[i+1]);
if(h>=1&&h<n){ //越界判断
if(nnn[h-1]){ //重复判断
cout<<"Not jolly"<<endl;
return 0;
}else nnn[h-1]=1;
}else{
cout<<"Not jolly"<<endl;
return 0;
}
}

int c=0;
for(int i=0;i<n;i++){
if(nnn[i]) c++;
}

if(c==n-1) cout<<"Jolly"<<endl;

return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*-------------------------------------------/
P1151 子数整数
https://www.luogu.com.cn/problem/P1151
/-------------------------------------------*/

/*
对于一个五位数a1a2a3a4a5,可将其拆分为三个子数:
sub1=a1a2a3
sub2=a2a3a4
sub3=a3a4a5
例如,五位数20207可以拆分成
sub1=202
sub2=020(=20)
sub3=207
现在给定一个正整数K,要求你编程求出10000到30000之间所有满足下述条件的五位数,
条件是这些五位数的三个子数sub1,sub2,sub3都可被K整除。
*/

//https://www.luogu.com.cn/record/55255820 (忽略了无解时的No输出)
//https://www.luogu.com.cn/record/55255846

#include<iostream>
using namespace std;
int main(){
int in;
cin>>in;
char num[5]={'1','0','0','0','0'};
int m=0;
for(int i=10000;i<=30000;i++){
for(int o=4;o>=0;o--){
if(num[o]>'9'){
num[o-1]++;
num[o]='0';
}
}
int fd=0;
for(int o=0;o<=2;o++){
int n=0;
n+=((num[o]-'0')*100)+((num[o+1]-'0')*10)+(num[o+2]-'0');
if(n%in==0){
fd++;
}
}
if(fd==3){
cout<<i<<endl;
m++;
}
num[4]++;
}
if(m==0){
cout<<"No"<<endl;
}
return 0;
}
0%