列表

详情


NC25399. HRY and ec-final

描述

yang12138 participated in the ec-final of 8102. Though he was good at number theory, he did not succeed in solving one of the number theory problem. This made him feel very angry. After the contest, he came up with a more difficult (?) number theory problem. He was so mad that he took the problem to this contest. Can you solve it?

There is an integer sequence S(index from 1) of length , which is composed of :
where represents the Euler function of n.

The definition of the Euler function is given below:
= Number of integers in 1-n which is coprime with n.
The Euler function values of 1,2,...,9,10 are 1,1,2,2,4,2,6,4,6,4

Given a sequence of numbers T(index from 1) with length of 300. He wants to know if this sequence is a contiguous subsequence of S. That is, whether there exists an i such that . If exists, output the smallest i, otherwise output "yang12138 laji"(without quotes).

输入描述

The input has 30 lines, ten positive integers per line, representing the sequence T.

输出描述

If the sequence T is a contiguous subsequence of S, output the smallest position i, otherwise output "yang12138 laji", without quotes.

示例1

输入:

1 1 2 2 4 2 6 4 6 4
10 4 12 6 8 8 16 6 18 8
12 10 22 8 20 12 18 12 28 8
30 16 20 16 24 12 36 18 24 16
40 12 42 20 24 22 46 16 42 20
32 24 52 18 40 24 36 28 58 16
60 30 36 32 48 20 66 32 44 24
70 24 72 36 40 36 60 24 78 32
54 40 82 24 64 42 56 40 88 24
72 44 60 46 72 32 96 42 60 40
100 32 102 48 48 52 106 36 108 40
72 48 112 36 88 56 72 58 96 32
110 60 80 60 100 36 126 64 84 48
130 40 108 66 72 64 136 44 138 48
92 70 120 48 112 72 84 72 148 40
150 72 96 60 120 48 156 78 104 64
132 54 162 80 80 82 166 48 156 64
108 84 172 56 120 80 116 88 178 48
180 72 120 88 144 60 160 92 108 72
190 64 192 96 96 84 196 60 198 80
132 100 168 64 160 102 132 96 180 48
210 104 140 106 168 72 180 108 144 80
192 72 222 96 120 112 226 72 228 88
120 112 232 72 184 116 156 96 238 64
240 110 162 120 168 80 216 120 164 100
250 72 220 126 128 128 256 84 216 96
168 130 262 80 208 108 176 132 268 72
270 128 144 136 200 88 276 138 180 96
280 92 282 140 144 120 240 96 272 112
192 144 292 84 232 144 180 148 264 80

输出:

1

示例2

输入:

1 1 2 2 4 2 6 4 6 4
10 4 12 6 8 8 16 6 18 8
12 10 22 8 20 12 18 12 28 8
30 16 20 16 24 12 36 18 24 16
40 12 42 20 24 22 46 16 42 20
32 24 52 18 40 24 36 28 58 16
60 30 36 32 48 20 66 32 44 24
70 24 72 36 40 36 60 24 78 32
54 40 82 24 64 42 56 40 88 24
72 44 60 46 72 32 96 42 60 40
100 32 102 48 48 52 106 36 108 40
72 48 112 36 88 55 72 58 96 32
110 60 80 60 100 36 126 64 84 48
130 40 108 66 72 64 136 44 138 48
92 70 120 48 112 72 84 72 148 40
150 72 96 60 120 48 156 78 104 64
132 54 162 80 80 82 166 48 156 64
108 84 172 56 120 80 116 88 178 48
180 72 120 88 144 60 160 92 108 72
190 64 192 96 96 84 196 60 198 80
132 100 168 64 160 102 132 96 180 48
210 104 140 106 168 72 180 108 144 80
192 72 222 96 120 112 226 72 228 88
120 112 232 72 184 116 156 96 238 64
240 110 162 120 168 80 216 120 164 100
250 72 220 126 128 128 256 84 216 96
168 130 262 80 208 108 176 132 268 72
270 128 144 136 200 88 276 138 180 96
280 92 282 140 144 120 240 96 272 112
192 144 292 84 232 144 180 148 264 80

输出:

yang12138 laji

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 11ms, 内存消耗: 588K, 提交时间: 2019-04-28 14:08:11

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[305];
int eular(int n)
{
    int res=n,a=n;
    for(int i=2;i*i<=a;i++)
    {
        if(a%i==0)
        {
           res=res/i*(i-1);
           while(a%i==0)a/=i;
        }
    }
    if(a>1)res=res/a*(a-1);
    return res;
}
bool check(int dis)
{
    for(int j=0;j<300;j++)
    {
        if(eular(dis+j)!=a[j])
        {
            return false;
        }
    }
    return true;
}
int main()
{
    for(int i=0;i<300;i++) scanf("%d",&a[i]);
    int ans=*max_element(a,a+300)-(max_element(a,a+300)-a)+1;
    if(!check(ans)||ans+299>1e9)cout<<"yang12138 laji"<<endl;
    else cout<<ans<<endl;
    return 0;
}

C++14(g++5.4) 解法, 执行用时: 43ms, 内存消耗: 468K, 提交时间: 2019-04-28 10:41:12

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll getphi(ll x){
	ll ans=x;
	for(int i=2;i<=x/i;i++){
		if(x%i==0){
			ans=ans*(i-1)/i;
			while(x%i==0)x/=i;
		}
	}
	if(x>1)ans=ans*(x-1)/x;
	return ans;
}
ll a[505];
int main(){
	int t=-1;ll maxx;
	for(int i=0;i<300;i++){
		scanf("%lld",&a[i]);
		if(t==-1||a[t]<a[i])t=i;
	}
	maxx=a[t];
	ll st=maxx+1-t;
	if(st+300-1>1e9)puts("yang12138 laji");
	else{
		bool f=1;
		for(ll i=st;i<st+300;i++)
			if(getphi(i)!=a[i-st]){f=0;break;}
		if(f)printf("%lld\n",st);
		else puts("yang12138 laji");
	}
	
	
	return 0;
} 

上一题