1 solutions

  • 0
    @ 2025-11-5 19:39:25

    C :

    #include<stdio.h>
    int main()
    {
    	int n, i, a, b, c;
    	while(scanf("%d",&n) != EOF)
    	{
    		a = 1;
    		b = 2;
    		c = 3;
    		for(i = 2; i <= n; i++)
    		{
    			c = (a + b) % 3;
    			a = b;
    			b = c;
    		}
    		if(c == 0)
    			puts("yes");
    		else
    			puts("no");
    		
    	}
    	
    	return 0;	
    }
    

    C++ :

    #include <cstdio>
    const int V = 1000000 + 50;
    int num[V];
    int main() {
        int i, n;
        num[0] = 1;
        num[1] = 2;
        for(i = 2; i < V; ++i)
            num[i] = (num[i - 1] + num[i - 2]) % 3;
        while(~scanf("%d", &n))
            printf("%s\n", num[n] ? "no" : "yes");
    }
    
    • 1

    Information

    ID
    19507
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By